From a5693b847456b746173057a2fb86d9573f53e9dd Mon Sep 17 00:00:00 2001 From: contr Date: Fri, 23 Oct 2026 19:47:26 +0300 Subject: [PATCH] fix: require review for unsupported mapping hints --- README.md | 2 +- docs/AGENT_GUIDE.md | 2 +- docs/PROJECT_BINDINGS.md | 4 +- docs/PROJECT_CHECKS.md | 15 +++++++- docs/ROADMAP.md | 6 ++- scripts/project_binding.py | 12 +++--- scripts/project_target.py | 43 +++++++++++++++++---- tests/test_project_binding.py | 22 +++++++++++ tests/test_project_target.py | 72 +++++++++++++++++++++++++++++++++++ 9 files changed, 159 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 28333ad..9690da2 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ python scripts/mcsource.py prepare --jar .local/inputs/client.jar --project /pat `verify` compares the local SHA-1 and byte size against Mojang's official client metadata over HTTPS, without downloading Minecraft. It reports `verified`, `mismatch`, or `unverified`; network errors never count as success. `prepare --verify-official` requires a verified result before tool downloads or source generation and stores the verification evidence. See [official verification](docs/OFFICIAL_VERIFICATION.md). -`check-project` compares supported static version declarations with the input JAR and prints evidence as JSON. It never runs Gradle or writes to the mod project. See [project checks](docs/PROJECT_CHECKS.md) for the supported syntax and limitations. A matching declaration is not proof of effective build configuration or API compatibility. +`check-project` compares supported static version declarations with the input JAR and prints evidence as JSON. It never runs Gradle or writes to the mod project. See [project checks](docs/PROJECT_CHECKS.md) for the supported syntax and limitations. Mapping hints and their file/line evidence appear under `namespace_review`. Unsupported or multiple mapping hints require review and block project preparation/binding. A matching declaration is not proof of effective build configuration or API compatibility. `prepare --project` blocks unknown, conflicting, or mismatching declarations before downloading tools or creating an output directory. It records a matching declaration report in the reference identity. This optional version gate does not replace the agent's namespace review. Omitting `--project` keeps standalone source preparation available. diff --git a/docs/AGENT_GUIDE.md b/docs/AGENT_GUIDE.md index c4a802c..71377dd 100644 --- a/docs/AGENT_GUIDE.md +++ b/docs/AGENT_GUIDE.md @@ -5,7 +5,7 @@ 1. Identify the target mod project and the user-supplied Minecraft JAR. Ask only for missing paths. Read the project's own instructions first. 2. Inspect only build configuration needed to identify the exact Minecraft version, loader, Java requirements, and mapping namespace. Do not infer values you cannot resolve. 3. Run `check-project --jar --project ` from the kit root. On `version_mismatch`, stop and request the correct input. On `needs_review`, inspect the evidence and resolve the actual target manually; never treat unknown as compatible. On `declared_version_match`, still check the effective configuration and namespace: this is a bounded declaration check, not Gradle evaluation. Review project instructions and any known property overrides. Use `inspect` for standalone JAR metadata and bytecode. For a claimed official client JAR, use `verify --jar ` for standalone provenance diagnostics, or enforce verification during preparation as described below. A successful project check alone does not verify provenance. -4. Check the namespace explicitly. Old obfuscated JARs need matching mappings; this first version cannot remap them. Do not treat raw obfuscated output as matching a named project. Do not silently substitute another Minecraft version. +4. Inspect `namespace_review` and its file/line evidence. Yarn, Intermediary, Parchment, multiple mapping hints, unsupported source labels, or a known unnamed input require review and block project preparation/binding. Do not bypass these warnings with standalone preparation or a hand-edited binding. Check the namespace explicitly. Old obfuscated JARs need matching mappings; this first version cannot remap them. Do not treat raw obfuscated output as matching a named project. Do not silently substitute another Minecraft version. 5. Run `prepare --jar --project --verify-official --repair` only after the effective target and namespace have been reviewed. The project option adds a version gate and stores its evidence. Official verification requires matching client SHA-1 and size from Mojang metadata. If verification is unavailable, report the reason and stop; do not silently drop the flag. An explicitly requested offline or modified-JAR workflow may use standalone preparation without the flag, with provenance left unverified. A known fingerprint mismatch must be resolved or explicitly identified as a modified input before proceeding. If the static parser cannot handle a project, explain the limitation and verify the actual target with the agent before using standalone `prepare`; do not bypass an unresolved mismatch. It builds the pinned CFR tool and creates a new output directory without modifying the target project. 6. Inspect `REFERENCE.json`, the CFR summary, and a few relevant source files. Report incomplete methods. Verify affected behavior against `javap` or a second official decompiler before relying on it. With `--repair`, reported CFR classes receive one conservative Vineflower attempt. Inspect the `fallback` record; `recovered_unverified` is not a correctness guarantee. If unresolved, stop relying on affected methods. For an existing kit reference use `repair --jar --reference `; it checks the original SHA-256. Do not delete attempt records or retry automatically. 7. Keep diagnostics and original-source backups. Successful recovery removes only its temporary class/output workspace. On failure, preserve it for diagnosis. Do not delete the repository, input JAR, tool cache, or source reference as setup cleanup. diff --git a/docs/PROJECT_BINDINGS.md b/docs/PROJECT_BINDINGS.md index 7b101f2..ce223fc 100644 --- a/docs/PROJECT_BINDINGS.md +++ b/docs/PROJECT_BINDINGS.md @@ -11,7 +11,7 @@ Quote paths containing spaces. Neither command requires the original JAR, Java, ## Creating a binding -The reference must be inside this kit's `.local/references/`, have a valid completed identity (`generated_unverified`), contain the recorded number of Java files, and have no known source failure markers. Unresolved/failed references and marked validation fixtures cannot be bound. Supported project version declarations must match the reference version; unsupported builds still need a supported resolution workflow rather than a guessed binding. +The reference must be inside this kit's `.local/references/`, have a valid completed identity (`generated_unverified`), contain the recorded number of Java files, and have no known source failure markers. Unresolved/failed references and marked validation fixtures cannot be bound. Supported project version declarations must match the reference version and pass the namespace review gates; unsupported builds still need a supported resolution workflow rather than a guessed binding. A file under `.local/bindings/` is keyed by the canonical project path. It stores: @@ -31,7 +31,7 @@ The snapshot detects changes after binding. It does not authenticate sources aga - `stale` (exit 2): inspected configuration, source identity, or active sources changed or became unavailable. The result includes reasons and deliberately omits the source-use instruction. - Invalid inputs or malformed binding files produce a diagnostic and exit 1. -`resolve` is read-only. It never repairs, rebinds, downloads, runs builds, or substitutes another source version. Its configuration scope is the same bounded root-file inspection documented in PROJECT_CHECKS.md. External Gradle overrides are not detected. Changes to the kit's own parser may also require review. +`resolve` is read-only. It never repairs, rebinds, downloads, runs builds, or substitutes another source version. Its configuration scope is the same bounded root-file inspection documented in PROJECT_CHECKS.md. Current project/reference checks, including namespace review gates, are re-run even for older bindings. External Gradle overrides are not detected. Changes to the kit's own parser may also require review. A coding agent still needs to know where this kit is. Bindings do not register themselves with Codex or other agents, and do not make external instructions load automatically. Give the agent the kit path, or manually add the returned instruction to the mod project's existing instructions. The kit does not write that instruction for you. diff --git a/docs/PROJECT_CHECKS.md b/docs/PROJECT_CHECKS.md index 5c0b986..8c81a11 100644 --- a/docs/PROJECT_CHECKS.md +++ b/docs/PROJECT_CHECKS.md @@ -22,7 +22,7 @@ Duplicate properties, conflicting versions, version ranges, unresolved expressio - `declared_version_match` (exit 0): supported declarations agree with the JAR's version label. This is not an API compatibility approval. - `version_mismatch` (exit 1): the supported unambiguous declarations name another version. Stop setup with this JAR. -- `needs_review` (exit 2): the static checker cannot establish a single target. Read `issues` and resolve the actual configuration before proceeding. +- `needs_review` (exit 2): the static checker cannot establish a single target, or namespace review gates block use. Read project `issues` and `namespace_review.reasons`, then resolve the actual configuration before proceeding. - Invalid input produces an error diagnostic and exit 1. The JSON report includes the source file and line for version declarations, configuration file SHA-256 values, and mapping/loader hints. Values are not inferred from installed caches or remembered version conventions. Only relevant declaration evidence is included, not complete build files. @@ -38,3 +38,16 @@ The JAR's namespace and provenance remain unverified by this command. A version ## Validation boundary Automated coverage uses small synthetic mod configurations and JARs. An integration smoke check used the local 26.2 JAR with matching 26.2 and mismatching 26.1 synthetic mod configurations; both statuses and project-file preservation were verified. This does not establish support for a real user's entire Gradle build. Real-project validation remains an acceptance gate. + +## Namespace review gates + +The report now includes `namespace_review` with static mapping hints, file/line evidence, source labels, reasons, and a `blocking` flag. No positive namespace-compatibility result is produced. + +- Yarn, Intermediary, and Parchment hints require review because this kit does not perform the required mapping transformations. +- Multiple mapping hints require review. This may describe a legitimate layered configuration; it is not automatically diagnosed as a broken build. +- Explicit unsupported source namespace labels or a known absence of the expected named client class also require review. +- A version mismatch remains `version_mismatch` even when namespace warnings are present. Otherwise blocking namespace reasons produce `needs_review` (exit 2). + +`prepare --project` and `bind` stop on that result before generating sources or writing bindings. `resolve` re-runs the current checks even for bindings created by an earlier kit; blocked old bindings become `stale` without a source-use instruction. + +An official Mojang mapping hint or absence of explicit mappings does not establish compatibility: the namespace result remains `unverified`. The checker is bounded static analysis; unrecognized custom mappings, plugins, catalogs, or external overrides may not produce a hint. An agent must still inspect the effective configuration. Ordinary comments and Parchment repository URLs alone are not mapping declarations. Do not bypass mapping warnings by omitting `--project` or editing a binding by hand. diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 51b8afb..e717068 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -10,7 +10,7 @@ ## Next acceptance gates -- Resolve project namespace compatibility beyond matching static version declarations and textual mapping hints. +- Expand namespace evidence beyond static review gates; full mapping resolution/conversion remains unsupported. - Validate additional Minecraft versions and real-project mismatch cases; the 26.2 read-only matching/binding workflow is documented in VALIDATION.md. - Compare representative API tasks with and without the kit. - Add preview-based, user-requested cache cleanup after the preparation workflow stabilizes; never remove active references or user inputs implicitly. @@ -46,3 +46,7 @@ A local smoke check paired the full 7,055-file 26.2 source reference with a synt ## Real-project validation A user-supplied Fabric mod targeting 26.2 passed read-only declaration checks and temporary binding/resolution against the full reference. Two sampled Minecraft API signatures matched. Project Git state and root configuration hashes were preserved; temporary validation data was cleaned. See [validation results](VALIDATION.md) for scope and limits. No mod build or in-game validation was performed. + +## Namespace review gates + +Static mapping evidence now blocks unsupported Yarn/Intermediary/Parchment, multiple hints, unsupported source labels, and known unnamed inputs at project preparation and binding. Resolution rechecks older bindings with the current gates. This is conservative review routing, not proof of compatibility or an automatic mapping converter. diff --git a/scripts/project_binding.py b/scripts/project_binding.py index f959690..e2d2fbb 100644 --- a/scripts/project_binding.py +++ b/scripts/project_binding.py @@ -113,13 +113,13 @@ def resolve_project(root, project): saved_check = binding.get("project_check") if not isinstance(saved_check, dict) or saved_check.get("status") != "declared_version_match" or not isinstance(saved_check.get("project"), dict): raise ValueError("Binding has no project configuration snapshot") - current = inspect_project(project) - if current["issues"] or current["declared_minecraft_version"] != saved_check["project"].get("declared_minecraft_version"): - reasons.append("project_target_needs_review") - if current["configuration_files"] != saved_check["project"].get("configuration_files"): - reasons.append("project_configuration_changed") try: reference, identity, record_hash = read_reference(root, root / binding["reference"]) + fresh_check = check_project(project, identity) + if fresh_check["status"] != "declared_version_match": + reasons.append("project_reference_review_required") + if fresh_check["project"]["configuration_files"] != saved_check["project"].get("configuration_files"): + reasons.append("project_configuration_changed") if record_hash != binding.get("reference_identity_sha256"): reasons.append("reference_identity_changed") elif not reasons and source_snapshot(reference) != binding.get("source_snapshot"): @@ -129,4 +129,4 @@ def resolve_project(root, project): reference = None if reasons: return {"status": "stale", "project_path": str(project), "reasons": reasons, "review_required": True} - return {"status": "located_unverified", "binding_file": str(target), "reference": str(reference), "project_check": saved_check, "review_required": True, "instruction": instruction(root, project, reference)} + return {"status": "located_unverified", "binding_file": str(target), "reference": str(reference), "project_check": fresh_check, "review_required": True, "instruction": instruction(root, project, reference)} diff --git a/scripts/project_target.py b/scripts/project_target.py index 76702ba..a0d8bc6 100644 --- a/scripts/project_target.py +++ b/scripts/project_target.py @@ -23,6 +23,7 @@ def inspect_project(path): properties = {} versions = [] mapping_hints = set() + mapping_evidence = [] loader_hints = set() files = [] builds = [] @@ -68,12 +69,15 @@ def inspect_project(path): loader_hints.add("neoforge") if "net.minecraftforge" in text: loader_hints.add("forge") - if "officialMojangMappings" in text: - mapping_hints.add("mojang") - if "net.fabricmc:yarn:" in text: - mapping_hints.add("yarn") - if "parchment" in text.lower(): - mapping_hints.add("parchment") + for hint, pattern in ( + ("mojang", r"\bofficialMojangMappings\s*\("), + ("yarn", r"net\.fabricmc:yarn:"), + ("intermediary", r"net\.fabricmc:intermediary:"), + ("parchment", r"org\.parchmentmc(?:\.data)?:|\bparchment\s*\("), + ): + for match in re.finditer(pattern, text): + mapping_hints.add(hint) + mapping_evidence.append({"file": name, "line": text.count("\n", 0, match.start()) + 1, "hint": hint}) for match in COORDINATE.finditer(text): dependency_found = True quote, coordinate = match.groups() @@ -99,23 +103,48 @@ def inspect_project(path): "project_path": str(root), "configuration_files": files, "declared_minecraft_version": exact[0] if len(exact) == 1 and not issues else None, "version_candidates": exact, "evidence": evidence, "issues": issues, - "mapping_hints": sorted(mapping_hints), "loader_hints": sorted(loader_hints), + "mapping_hints": sorted(mapping_hints), "mapping_evidence": mapping_evidence, "loader_hints": sorted(loader_hints), "inspection": "static_declarations_only", } +def namespace_review(project, identity): + """Conservative gates from static hints, never a namespace compatibility proof.""" + hints = project["mapping_hints"] + reasons = [] + if len(hints) > 1: + reasons.append("multiple_mapping_hints_require_review") + if any(hint != "mojang" for hint in hints): + reasons.append("mapping_transformation_not_supported") + if identity.get("namespace", "unverified") not in ("unverified", "mojang"): + reasons.append("source_namespace_not_supported") + if identity.get("named_client_class_present") is False: + reasons.append("named_client_source_not_established") + return { + "status": "needs_review" if reasons else "unverified", + "blocking": bool(reasons), "reasons": reasons, + "project_hints": hints, "evidence": project["mapping_evidence"], + "source_namespace": identity.get("namespace", "unverified"), + "named_client_class_present": identity.get("named_client_class_present"), + } + + def check_project(path, jar_identity): project = inspect_project(path) declared = project["declared_minecraft_version"] + namespace = namespace_review(project, jar_identity) if declared is None: status = "needs_review" elif declared != jar_identity["minecraft_version"]: status = "version_mismatch" + elif namespace["blocking"]: + status = "needs_review" else: status = "declared_version_match" return { "schema_version": 1, "status": status, "project": project, "jar": {key: jar_identity[key] for key in ("minecraft_version", "sha256", "namespace", "provenance", "scope")}, + "namespace_review": namespace, "api_compatibility": "unverified", "review_required": True, "limitations": [ diff --git a/tests/test_project_binding.py b/tests/test_project_binding.py index 030361b..bf452e5 100644 --- a/tests/test_project_binding.py +++ b/tests/test_project_binding.py @@ -161,6 +161,28 @@ def test_project_change_during_binding_is_rejected(self): self.bind() self.assertFalse((self.kit / ".local/bindings").exists()) + def test_mapping_review_blocks_binding_without_writing(self): + with (self.project / "build.gradle").open("a") as stream: + stream.write('\nmappings "net.fabricmc:yarn:26.2+build.1:v2"\n') + with self.assertRaisesRegex(ValueError, "matching supported"): + self.bind() + self.assertFalse((self.kit / ".local/bindings").exists()) + + def test_legacy_binding_is_rechecked_against_current_mapping_gates(self): + first = self.bind() + with (self.project / "build.gradle").open("a") as stream: + stream.write('\nmappings "net.fabricmc:yarn:26.2+build.1:v2"\n') + target = Path(first["binding_file"]) + legacy = json.loads(target.read_text()) + # Simulate an earlier kit accepting the same unchanged Yarn configuration. + legacy["project_check"]["project"] = binding.inspect_project(self.project) + target.write_text(json.dumps(legacy), encoding="utf-8") + report = self.resolve() + self.assertEqual(report["status"], "stale") + self.assertIn("project_reference_review_required", report["reasons"]) + self.assertNotIn("project_configuration_changed", report["reasons"]) + self.assertNotIn("instruction", report) + def test_cli_resolve_missing_binding(self): result = subprocess.run([sys.executable, str(SCRIPTS / "mcsource.py"), "resolve", "--project", str(self.project)], capture_output=True, text=True) self.assertEqual(result.returncode, 2) diff --git a/tests/test_project_target.py b/tests/test_project_target.py index 63dd1a4..f614514 100644 --- a/tests/test_project_target.py +++ b/tests/test_project_target.py @@ -108,6 +108,78 @@ def test_yarn_is_only_a_hint(self): self.assertIn("yarn", report["project"]["mapping_hints"]) self.assertEqual(report["api_compatibility"], "unverified") + def test_yarn_declaration_blocks_same_version_preparation(self): + self.write_project() + build = self.project / "build.gradle" + build.write_text(build.read_text().replace("mappings loom.officialMojangMappings()", 'mappings "net.fabricmc:yarn:26.2+build.1:v2"')) + report = self.report() + self.assertEqual(report["status"], "needs_review") + self.assertTrue(report["namespace_review"]["blocking"]) + self.assertEqual(report["namespace_review"]["evidence"][0], {"file": "build.gradle", "line": 4, "hint": "yarn"}) + with patch.object(mcsource, "ROOT", self.root), patch.object(mcsource, "build_cfr") as build_tool, patch.object(mcsource, "verify_official") as verify: + with self.assertRaisesRegex(ValueError, "needs_review"): + mcsource.prepare(self.jar, self.project, official=True) + build_tool.assert_not_called() + verify.assert_not_called() + self.assertFalse((self.root / ".local").exists()) + + def test_multiple_mapping_hints_are_not_an_automatic_match(self): + self.write_project() + with (self.project / "build.gradle").open("a") as stream: + stream.write('\nmappings "net.fabricmc:yarn:26.2+build.1:v2"\n') + report = self.report() + self.assertEqual(report["status"], "needs_review") + self.assertIn("multiple_mapping_hints_require_review", report["namespace_review"]["reasons"]) + + def test_intermediary_and_parchment_require_review(self): + for coordinate in ("net.fabricmc:intermediary:26.2", "org.parchmentmc.data:parchment-26.2:2026.10.01@zip"): + with self.subTest(coordinate=coordinate): + self.write_project() + build = self.project / "build.gradle" + build.write_text(build.read_text().replace("mappings loom.officialMojangMappings()", 'mappings "' + coordinate + '"')) + self.assertEqual(self.report()["status"], "needs_review") + + def test_commented_mappings_do_not_trigger_review(self): + self.write_project() + with (self.project / "build.gradle").open("a") as stream: + stream.write('\n// mappings "net.fabricmc:yarn:26.2:v2"\n/* parchment("example") */\n') + self.assertEqual(self.report()["status"], "declared_version_match") + + def test_repository_mention_is_not_a_parchment_mapping(self): + self.write_project() + with (self.project / "build.gradle").open("a") as stream: + stream.write('\nrepositories { maven { url "https://maven.parchmentmc.org" } }\n') + self.assertEqual(self.report()["project"]["mapping_hints"], ["mojang"]) + + def test_absent_mapping_declaration_remains_unverified(self): + self.write_project() + build = self.project / "build.gradle" + build.write_text(build.read_text().replace("mappings loom.officialMojangMappings()", "")) + report = self.report() + self.assertEqual(report["status"], "declared_version_match") + self.assertEqual(report["namespace_review"]["status"], "unverified") + self.assertEqual(report["namespace_review"]["project_hints"], []) + self.assertEqual(report["api_compatibility"], "unverified") + + def test_unnamed_input_requires_review(self): + self.write_project() + self.identity["named_client_class_present"] = False + report = self.report() + self.assertEqual(report["status"], "needs_review") + self.assertIn("named_client_source_not_established", report["namespace_review"]["reasons"]) + + def test_unsupported_source_namespace_requires_review(self): + self.write_project() + self.identity["namespace"] = "yarn" + self.assertEqual(self.report()["status"], "needs_review") + + def test_version_mismatch_stays_visible_with_mapping_warnings(self): + self.write_project(version="26.1") + self.identity["namespace"] = "yarn" + report = self.report() + self.assertEqual(report["status"], "version_mismatch") + self.assertTrue(report["namespace_review"]["blocking"]) + def test_project_tree_is_unchanged(self): self.write_project() before = {p.relative_to(self.project): hashlib.sha256(p.read_bytes()).hexdigest() for p in self.project.rglob("*") if p.is_file()}