From 81cbc2707eae37080f39e3044ddfbdaedd401df4 Mon Sep 17 00:00:00 2001 From: Jerry Date: Wed, 4 Nov 2026 15:54:00 +0800 Subject: [PATCH] fix(cli): map an external project's paths to the cheap gate Dogfooding on nova-survivors-gai found this: with `GAI_GAME` set, `next` matched `components/x.gd` only against the catch-all rule, so every script edit in a real project was sent to the full check. The table knew the `game/` prefix of the bundled starter game and nothing else. `next` now resolves a path against the project when the project is not the bundled one: a `.gd` gives `script` with a `res://` command, a file under `tests/` gives `check`, anything else gives `check`. The rule names are `/**/*.gd` and `/tests/**` so a reader can see which project they belong to. Measured on the real project: `check --script` for one script takes 7.9 s, which is the difference between a script gate and the 90-second full check. The same run recorded the rest of the dogfood: check ok with 15 autoloads, 35 scene tests, lint clean on 147 scripts, a 190.4 MiB Linux export that starts headless, `script.classes` answering with 94 classes, and locks plus the audit log working on a real scene. --- bin/gai | 28 +++++++++++++++++++++++++++- docs/gai/build.md | 4 ++++ docs/gai/decisions/worklog.tsv | 2 ++ tests/test_next.py | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/bin/gai b/bin/gai index 4913766ab8..075a034699 100755 --- a/bin/gai +++ b/bin/gai @@ -2449,12 +2449,38 @@ def normalize_path(path: str) -> str: return text +def game_relative(path: str) -> str: + """The path relative to the game project, when it is inside one. + + A game outside this repository has no `game/` prefix, so the table alone + would send every script edit to the full check. + """ + if GAME_SOURCE == "bundled starter game": + return "" + for candidate in (Path(path), Path.cwd() / path, GAME_DIR / path): + try: + relative = candidate.resolve().relative_to(GAME_DIR.resolve()) + except (ValueError, OSError): + continue + return relative.as_posix() + return "" + + def next_rule(path: str): """Return the first table rule that matches a path, as (gate, pattern).""" candidates = [path] if path.endswith("/"): # `git status` reports a whole new folder, not its files: probe inside it. candidates.append(path.rstrip("/") + "/_") + for candidate in candidates: + relative = game_relative(candidate) + if not relative: + continue + if relative.startswith("tests/"): + return "check", "/tests/**" + if relative.endswith(".gd"): + return "script", "/**/*.gd" + return "check", "/**" for candidate in candidates: for regex, gate, pattern in NEXT_COMPILED: if regex.match(candidate): @@ -2494,7 +2520,7 @@ def res_path(path: str) -> str: return path candidate = Path(path) if not candidate.is_absolute(): - candidate = ROOT / path + candidate = GAME_DIR / path if (GAME_DIR / path).exists() else ROOT / path try: return "res://" + candidate.resolve().relative_to(GAME_DIR.resolve()).as_posix() except (ValueError, OSError): diff --git a/docs/gai/build.md b/docs/gai/build.md index ce9007c202..f013a6b736 100644 --- a/docs/gai/build.md +++ b/docs/gai/build.md @@ -229,6 +229,10 @@ It is the highest gate of the paths it was given: | `*.md`, `docs/`, `AGENTS.md`, `tests/*.py`, `.github/` | `none` | nothing | | anything else | `check` | `bin/gai check` | +For a project outside this repository, `next` reads paths relative to the project +instead of `game/`: a `.gd` there gives `script`, a file under `tests/` gives +`check`, and anything else gives `check`. + A file under `game/tests/` gives `check`, not `script`. A path that git reports as deleted gives `check` too, because a missing script cannot be compiled and the scenes that referenced it are what still needs a gate. diff --git a/docs/gai/decisions/worklog.tsv b/docs/gai/decisions/worklog.tsv index 276a34b771..558e3fc849 100644 --- a/docs/gai/decisions/worklog.tsv +++ b/docs/gai/decisions/worklog.tsv @@ -65,3 +65,5 @@ ts phase decision why evidence result 2026-11-04T03:50:00+08:00 feature `stub_once` answers in turn, and a double of a subclass overrides methods its base script declares. The roadmap's own test-maturity leftover: every fixture needed a wrapper script to be stubbable, and a fixed sequence had no way to be tested. game/tests/gai_test_case.gd; game/tests/test_doubles.gd; docs/gai/testing.md 17 game tests pass, including an inherited `take_damage` and a three-call sequence. 2026-11-04T03:55:00+08:00 fix CODEOWNERS covers `/game/` and `/tests/*.py` instead of a list of test files. validate-codeowners failed on every game file an agent touches, which is most edits in this repository. .github/CODEOWNERS validate-codeowners passes for game and test files. 2026-11-04T04:15:00+08:00 fix test_lint asserts the shape of the script count, not the number. A new fixture script made a hard-coded "lint: 8 scripts" fail in CI while the lint itself was clean. tests/test_lint.py The assertion is a regex over "lint: scripts, 0 problems"; 11 lint tests pass. +2026-11-04T04:40:00+08:00 dogfood Ran gai against nova-survivors-gai: doctor, check, 35 scene tests, lint, a Linux export, and the new bridge features. The roadmap's dogfood item needs a real project, and it exists on this machine; nothing in a synthetic starter game exercises 15 autoloads, 94 class_names, or a 190 MiB export. ~/nova-survivors-gai; bin/gai export linux check ok, 35 scene tests pass, lint 147 scripts 0 problems, export 190.4 MiB starts headless, script.classes returns 94 classes, locks and audit behave on the real scene. +2026-11-04T04:50:00+08:00 fix `next` maps a path inside an external project to the script, test, and check gates, instead of sending every script edit to the full check. Dogfooding found it: with GAI_GAME set, `components/x.gd` matched only the catch-all rule, so the cheap gate never applied to a real project. bin/gai; tests/test_next.py; docs/gai/build.md An external project .gd gives gate script with res://components/ability.gd and check --script runs in 7.9 s on the real project. diff --git a/tests/test_next.py b/tests/test_next.py index 0ff57ecd9c..f0e6db0a9e 100755 --- a/tests/test_next.py +++ b/tests/test_next.py @@ -2,6 +2,7 @@ """Tests for bin/gai next. These do not need SCons or an engine.""" import json +import os import shutil import subprocess import sys @@ -26,15 +27,46 @@ def setUp(self): encoding="utf-8", ) - def run_gai(self, *args): + def run_gai(self, *args, env=None): return subprocess.run( [sys.executable, str(self.tmp / "bin" / "gai"), *args], cwd=str(self.tmp), text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=env, ) + def external_game(self): + """A project outside the repository, the way GAI_GAME points at one.""" + project = self.tmp / "external" + (project / "components").mkdir(parents=True) + (project / "tests").mkdir() + (project / "project.godot").write_text("config_version=5\n", encoding="utf-8") + for path in ("components/ability.gd", "components/scene.tscn", "tests/p0_test.gd"): + (project / path).write_text("extends Node\n", encoding="utf-8") + env = dict(os.environ) + env["GAI_GAME"] = str(project) + return project, env + + def test_external_project_scripts_use_the_script_gate(self): + project, env = self.external_game() + result = self.run_gai("next", "--json", str(project / "components" / "ability.gd"), env=env) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + payload = json.loads(result.stdout) + self.assertEqual(payload["gate"], "script") + self.assertEqual(payload["reasons"][0]["rule"], "/**/*.gd") + self.assertEqual( + payload["command"], + "bin/gai check --script res://components/ability.gd --no-run", + ) + + relative = self.run_gai("next", "--json", "components/scene.tscn", env=env) + self.assertEqual(json.loads(relative.stdout)["gate"], "check") + + tests = self.run_gai("next", "--json", "tests/p0_test.gd", env=env) + self.assertEqual(json.loads(tests.stdout)["reasons"][0]["rule"], "/tests/**") + def gate(self, *paths): result = self.run_gai("next", *paths) self.assertEqual(result.returncode, 0, result.stdout + result.stderr)