Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion bin/gai
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<game>/tests/**"
if relative.endswith(".gd"):
return "script", "<game>/**/*.gd"
return "check", "<game>/**"
for candidate in candidates:
for regex, gate, pattern in NEXT_COMPILED:
if regex.match(candidate):
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions docs/gai/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/gai/decisions/worklog.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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: <n> 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.
34 changes: 33 additions & 1 deletion tests/test_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"], "<game>/**/*.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"], "<game>/tests/**")

def gate(self, *paths):
result = self.run_gai("next", *paths)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
Expand Down
Loading