Skip to content

Commit c0e88a6

Browse files
committed
fix(docs): address CodeRabbit review comments on PR #451
- project_release_pipeline_gotchas.md: fix "three issues" wording to match the actual four numbered items, and complete the shouldPerformUpdateCheck() gate description (was missing the non-upgrade exclusion). - PRD: reconcile the contradictory v1 scope statement — TS/JS ship in v1, Python/Ruby follow per the rollout sequencing section, not both in v1 as the requirements line previously implied. - ARCH-022: fix "sandbst" typo; require the interpreter-availability probe to try platform-appropriate candidate names (python3 is not a universal PATH alias on Windows) per ARCH-009; clarify that the two ctx.ast() throw cases (missing interpreter vs. parse failure) must be distinguishable in the error message text even though they share exit code 2. Workflow-file findings (persist-credentials, template-injection, TAG interpolation) from the same review were already resolved by the origin/main merge in a prior commit — verified against current file state, no further changes needed there. Signed-off-by: Rhuan Barreto <rhuan@barreto.work>
1 parent d1b9b38 commit c0e88a6

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎.archgate/PRDs/ast-aware-rule-context.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Representative use cases:
4040
### Functional
4141

4242
- `RuleContext` MUST expose the AST capability as a single method taking a file path and a language identifier, returning the parsed tree or throwing (see ARCH-022 for the exact signature and throw semantics).
43-
- Supported languages for v1: TypeScript, JavaScript, Python, Ruby.
43+
- Supported languages overall: TypeScript, JavaScript, Python, Ruby. TypeScript/JavaScript ship in v1; Python/Ruby follow in a later release per the rollout sequencing below.
4444
- The method MUST work against any file within the rule's `scopedFiles`/`changedFiles`, subject to the same sandboxing already applied to `readFile`/`glob`.
4545

4646
### Rollout Sequencing

‎.archgate/adrs/ARCH-022-ast-aware-rule-context.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ This method dispatches internally based on `language`, and the dispatch mechanis
3939

4040
1. **Path safety** — the requested `path` MUST pass through the same `safePath()` sandboxing already applied to `readFile`/`glob` (no traversal outside `scopedFiles`, no symlink escapes).
4141
2. **Language plausibility check** — the file's extension and/or leading content MUST be sanity-checked against the requested `language` before any interpreter is invoked on it. A rule calling `ctx.ast("config.json", "python")` MUST fail this check rather than hand arbitrary file content to `python3`.
42-
3. **Interpreter availability probe** — for `"python"`/`"ruby"`, an availability check (e.g. `Bun.spawn(["python3", "--version"])` wrapped in `try/catch`, following the exact pattern `isClaudeCliAvailable()` uses in ARCH-007) MUST run before the real invocation. This probe result MUST be cached once per `check` invocation, not re-run per file.
42+
3. **Interpreter availability probe** — for `"python"`/`"ruby"`, an availability check (e.g. `Bun.spawn([candidate, "--version"])` wrapped in `try/catch`, following the exact pattern `isClaudeCliAvailable()` uses in ARCH-007) MUST run before the real invocation. `python3` is not a universal PATH alias on Windows (the common installer exposes `python`, not `python3`); the probe MUST try platform-appropriate candidate executable names in order (e.g. `python3` then `python` on non-Windows, `python` then `python3` on Windows, using [ARCH-009](./ARCH-009-platform-detection-helper.md)'s `isWindows()`) and use the first one that resolves for both the probe and the real invocation. This probe result MUST be cached once per `check` invocation, not re-run per file.
4343
4. **Guarded invocation** — the actual `Bun.spawn` call MUST use array-based arguments only, per ARCH-007, with no shell interpolation of file contents or paths.
4444

45-
**Failure semantics.** `ctx.ast()` MUST throw — it MUST NOT return `null` or any other sentinel — both when the required interpreter is unavailable and when the target file fails to parse. This is a deliberate choice, not an oversight: this ADR does not introduce any new error-boundary or exit-code behavior, and none is needed, because `ctx.ast()`'s failure mode composes directly with contracts `src/engine/runner.ts` and `src/engine/reporter.ts` already implement. Every rule's `check(ctx)` call already runs inside a per-rule `try/catch` (`runner.ts`, the loop over `Object.entries(ruleSet.rules)`) that isolates a thrown error to that single rule — other ADRs and rules in the same `check` run continue and report normally. `reporter.ts`'s `getExitCode()` already reserves exit code `2` specifically for rule execution errors, distinct from exit `1` (ADR violations found) and exit `0` (pass). A thrown `ctx.ast()` error therefore surfaces as a visible, correctly-categorized failure through machinery that already exists; a `null` return would instead let a rule silently no-op and report as a false "0 violations," masking a real capability gap as a pass.
45+
**Failure semantics.** `ctx.ast()` MUST throw — it MUST NOT return `null` or any other sentinel — both when the required interpreter is unavailable and when the target file fails to parse. This is a deliberate choice, not an oversight: this ADR does not introduce any new error-boundary or exit-code behavior, and none is needed, because `ctx.ast()`'s failure mode composes directly with contracts `src/engine/runner.ts` and `src/engine/reporter.ts` already implement. Every rule's `check(ctx)` call already runs inside a per-rule `try/catch` (`runner.ts`, the loop over `Object.entries(ruleSet.rules)`) that isolates a thrown error to that single rule — other ADRs and rules in the same `check` run continue and report normally. `reporter.ts`'s `getExitCode()` already reserves exit code `2` specifically for rule execution errors, distinct from exit `1` (ADR violations found) and exit `0` (pass). A thrown `ctx.ast()` error therefore surfaces as a visible, correctly-categorized failure through machinery that already exists; a `null` return would instead let a rule silently no-op and report as a false "0 violations," masking a real capability gap as a pass. The exit-code/reporter distinction is coarse by design (exit `2` means "a rule could not complete," full stop) — the two throw cases MUST still be distinguishable from each other in the thrown error's message text (e.g. "Python interpreter not found on PATH" vs. "Failed to parse `<path>`: `<parser error>`"), since a user reading `check` output needs to tell "this environment can't run this rule" apart from "this specific file has a syntax error" even though both land on the same exit code.
4646

4747
**Explicit non-goal: cross-language AST shape unification.** `ctx.ast()` unifies the call site and the failure contract across languages. It does NOT unify the shape of the returned tree. TypeScript/JavaScript returns ESTree-shaped nodes (via `meriyah`); Python returns whatever the standard `ast` module's own node schema produces; Ruby returns `Ripper`'s native s-expression shape. A rule author writing a Python check and a rule author writing a Ruby check are working against two different, language-native grammars, and must know the target language's own AST vocabulary. This ADR accepts that trade explicitly in exchange for avoiding the dependency and distribution cost of a unifying parser (see the tree-sitter alternatives above); it is not a limitation to be silently discovered later.
4848

@@ -89,7 +89,7 @@ This method dispatches internally based on `language`, and the dispatch mechanis
8989
### Risks
9090

9191
- **A future contributor bypasses the guardrail ordering and spawns `python3`/`ruby` directly from inside a `ctx.ast()` code path without the path-safety or language-plausibility checks.**
92-
- **Mitigation:** the four-step guardrail ordering in the Decision section is mandatory and reviewable; `rule-scanner.ts`'s existing `BLOCKED_BUN_PROPS` sandbst continues to prevent `.rules.ts` files themselves from reaching `Bun.spawn`, so the only code path capable of spawning a subprocess for this feature is `createRuleContext()` itself, which code review MUST verify follows the ordering exactly.
92+
- **Mitigation:** the four-step guardrail ordering in the Decision section is mandatory and reviewable; `rule-scanner.ts`'s existing `BLOCKED_BUN_PROPS` sandbox continues to prevent `.rules.ts` files themselves from reaching `Bun.spawn`, so the only code path capable of spawning a subprocess for this feature is `createRuleContext()` itself, which code review MUST verify follows the ordering exactly.
9393
- **Interpreter-version skew between the machine authoring a Python/Ruby rule and machines running `archgate check` produces inconsistent AST shapes for the same source file.**
9494
- **Mitigation:** this is inherent to shelling out to system-installed interpreters rather than bundling a pinned parser version, and is accepted as part of choosing Option A over tree-sitter. Rule authors targeting Python/Ruby structural checks should keep patterns tolerant of minor version-specific node shape differences, and the interpreter-availability probe surfaces the interpreter's version so this can be logged for diagnosis.
9595
- **The duplicated inline `parseModule()` calls in `rule-scanner.ts` are not factored out before `ctx.ast()`'s TS/JS branch is implemented, leaving three near-identical parse call sites instead of two.**

‎.claude/agent-memory/archgate-developer/project_release_pipeline_gotchas.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ metadata:
55
type: project
66
---
77

8-
Three distinct issues caused shim/binary publishing failures across v0.45.1–v0.46.1, fixed in `fix/publish-shims-race`:
8+
Four distinct issues caused shim/binary publishing failures across v0.45.1–v0.46.1, fixed in `fix/publish-shims-race`:
99

1010
1. **Workflow race**: `publish-shims.yml` and `release-binaries.yml` both triggered on `release: published`. If binaries needed a retry, `publish-shims.yml`'s fixed-budget `wait-for-binaries` poll timed out and went `cancelled` (terminal) before the retry finished. Fixed: `publish-shims.yml` is now `workflow_dispatch`-only; `release-binaries.yml`'s `trigger-shim-publish` job dispatches it via `gh workflow run` after binaries + provenance succeed.
1111
2. **`moonrepo/setup-toolchain` cache bug**: right after a `.prototools` bump, the first macOS/Windows CI run can restore a stale `restore-key` cache fallback instead of an exact hit — the action reports success but `bun` isn't on PATH. Log signature: `Cache hit for restore-key:` (vs. exact `Cache hit for:`). Self-heals on retry (the failing job still saves a fresh exact-key cache in post-job cleanup). No code fix — just don't chase it as flakiness.
12-
3. **Update-check stdout pollution**: `src/cli.ts` printed a background "update available" notice to stdout after every command, unconditionally. Broke `JSON.parse(stdout)` in CLI-subprocess tests (and would break real `| jq` usage) whenever a newer release existed. Fixed via `shouldPerformUpdateCheck()` in `src/helpers/update-check.ts` — only checks in a genuine TTY, non-CI session.
12+
3. **Update-check stdout pollution**: `src/cli.ts` printed a background "update available" notice to stdout after every command, unconditionally. Broke `JSON.parse(stdout)` in CLI-subprocess tests (and would break real `| jq` usage) whenever a newer release existed. Fixed via `shouldPerformUpdateCheck()` in `src/helpers/update-check.ts` — only checks in a genuine TTY, non-CI, non-`upgrade` session.
1313
4. **`publish-go-tag` missing `workflows: write`**: its `git push origin shims/go/$TAG` was rejected — GitHub blocks any ref push reachable through commits touching `.github/workflows/*` without that permission, even for an unrelated tag. Fixed by adding `workflows: write` to the job's `permissions:`. Confirmed on v0.45.7's job log.
1414

1515
**Why:** Diagnosed while investigating why v0.46.0/v0.46.1 kept failing to publish despite repeated manual retries.
16-
**How to apply:** If a release build fails and a retry "just works," check which of these three it was before assuming generic flakiness.
16+
**How to apply:** If a release build fails and a retry "just works," check which of these four it was before assuming generic flakiness.

0 commit comments

Comments
 (0)