This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 867ab4e54 build(server): enforce the character bar on collected 
license texts (#7094)
867ab4e54 is described below

commit 867ab4e5403a5a99068a9c61a9535a196296a917
Author: 0 <[email protected]>
AuthorDate: Fri Nov 27 11:58:10 2026 +0800

    build(server): enforce the character bar on collected license texts (#7094)
---
 server/scripts/legal.py      | 45 +++++++++++++++++++++++++-------------------
 server/scripts/legal_test.py | 38 +++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 19 deletions(-)

diff --git a/server/scripts/legal.py b/server/scripts/legal.py
index b93277380..8e3a82dff 100644
--- a/server/scripts/legal.py
+++ b/server/scripts/legal.py
@@ -148,25 +148,32 @@ def add_component(files, components, errors, name, 
payload, texts, notice, sourc
             except (OSError, ValueError) as failure:
                 errors.append(f"{name}: collected license text is unusable 
({source_path}): {failure}")
             else:
-                texts = dict(texts)
-                texts["LICENSE"] = collected
-                component["license"] = determination["license"]
-                component["basis"] = determination.get("basis", "")
-                component["textSource"] = 
f"server/{COLLECTED}/{determination['text']}"
-                # Any determination may carry an open question. Surfacing it 
on every build beats
-                # burying it in a JSON file nobody re-reads.
-                if determination.get("review") and determination["kind"] != 
"categoryB" and warnings is not None:
-                    warnings.append(f"{name}: {determination['license']} — 
{determination['review']}")
-                    component["review"] = determination["review"]
-                if determination["kind"] == "categoryB":
-                    review = determination.get("review")
-                    if not review:
-                        errors.append(f"{name}: ASF Category B 
({determination['license']}) is bundled "
-                                      f"without a recorded review decision")
-                    else:
-                        component["categoryBReview"] = review
-                        if warnings is not None:
-                            warnings.append(f"{name}: ASF Category B 
({determination['license']}) bundled — {review}")
+                if len(collected.strip()) < 300:
+                    # A collected text travels with the distribution in place 
of the jar's own
+                    # missing license, so it is held to the same bar as an 
embedded one; a stub
+                    # or truncated file must not silently become the 
component's terms.
+                    errors.append(f"{name}: collected license text 
{determination['text']} is only "
+                                  f"{len(collected.strip())} characters, under 
the 300-character bar")
+                else:
+                    texts = dict(texts)
+                    texts["LICENSE"] = collected
+                    component["license"] = determination["license"]
+                    component["basis"] = determination.get("basis", "")
+                    component["textSource"] = 
f"server/{COLLECTED}/{determination['text']}"
+                    # Any determination may carry an open question. Surfacing 
it on every build beats
+                    # burying it in a JSON file nobody re-reads.
+                    if determination.get("review") and determination["kind"] 
!= "categoryB" and warnings is not None:
+                        warnings.append(f"{name}: {determination['license']} — 
{determination['review']}")
+                        component["review"] = determination["review"]
+                    if determination["kind"] == "categoryB":
+                        review = determination.get("review")
+                        if not review:
+                            errors.append(f"{name}: ASF Category B 
({determination['license']}) is bundled "
+                                          f"without a recorded review 
decision")
+                        else:
+                            component["categoryBReview"] = review
+                            if warnings is not None:
+                                warnings.append(f"{name}: ASF Category B 
({determination['license']}) bundled — {review}")
     for filename, data in sorted(texts.items()):
         if not data.strip():
             errors.append(f"{name}: empty license file {filename}")
diff --git a/server/scripts/legal_test.py b/server/scripts/legal_test.py
index 2215d37bc..cecc37b5f 100644
--- a/server/scripts/legal_test.py
+++ b/server/scripts/legal_test.py
@@ -85,6 +85,44 @@ class LegalTest(unittest.TestCase):
         self.assertEqual(original, jar.read_bytes())
         self.assertTrue((self.directory / "legal/manifest.json").is_file())
 
+    def collectedFixture(self, text):
+        """A standalone gate base whose determinations table maps 
fixture-collected-1.0.jar
+        (artifact id fixture-collected) to a collected license text, standing 
in for a jar
+        that carries no embedded license of its own."""
+        base = self.directory / "gate-base"
+        (base / "scripts").mkdir(parents=True)
+        (base / "legal/licenses").mkdir(parents=True)
+        (base / "LICENSE").write_bytes(legal.read(legal.SERVER / "LICENSE"))
+        (base / "NOTICE").write_bytes(legal.read(legal.SERVER / "NOTICE"))
+        (base / "legal/licenses/fixture-collected.txt").write_bytes(text)
+        (base / "scripts/legal-determinations.json").write_text(json.dumps(
+            {"collected": {"fixture-collected": {"license": "Apache-2.0", 
"text": "fixture-collected.txt",
+                                                 "basis": "test fixture"}}}))
+        return base
+
+    def collectedDeterminationSuppliesMissingEmbeddedLicenseTest(self):
+        collected = legal.read(legal.SERVER / "LICENSE")
+        base = self.collectedFixture(collected)
+        jar = self.jar("fixture-collected-1.0.jar", license_present=False)
+        legal.package_jar(jar, self.directory / "legal", base=base)
+        legal.check_jar(jar, base=base)
+        with zipfile.ZipFile(jar) as archive:
+            self.assertEqual(collected, 
archive.read("META-INF/legal/licenses/fixture-collected-1.0.jar/LICENSE.txt"))
+        manifest = json.loads((self.directory / 
"legal/manifest.json").read_text())
+        component = [c for c in manifest["components"] if c["name"] == 
"fixture-collected-1.0.jar"][0]
+        self.assertEqual("Apache-2.0", component["license"])
+        self.assertEqual("server/legal/licenses/fixture-collected.txt", 
component["textSource"])
+        self.assertEqual("test fixture", component["basis"])
+
+    def shortCollectedTextStillFailsTest(self):
+        base = self.collectedFixture(b"fixture: too short to be a license 
text.\n" * 3)
+        jar = self.jar("fixture-collected-1.0.jar", license_present=False)
+        original = jar.read_bytes()
+        with self.assertRaisesRegex(ValueError, "300-character bar"):
+            legal.package_jar(jar, self.directory / "legal", base=base)
+        self.assertEqual(original, jar.read_bytes())
+        self.assertTrue((self.directory / "legal/manifest.json").is_file())
+
     def mysqlExceptionRequiresReviewTest(self):
         jar = self.jar("mysql-connector-j-9.7.0.jar")
         with self.assertRaisesRegex(ValueError, "Universal FOSS Exception"):

Reply via email to