@gate-forge/cli 0.6.3 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +126 -21
  2. package/dist/args.js +1 -1
  3. package/dist/args.js.map +1 -1
  4. package/dist/broker.d.ts.map +1 -1
  5. package/dist/broker.js +19 -10
  6. package/dist/broker.js.map +1 -1
  7. package/dist/candidate-tree.d.ts +2 -1
  8. package/dist/candidate-tree.d.ts.map +1 -1
  9. package/dist/candidate-tree.js +66 -4
  10. package/dist/candidate-tree.js.map +1 -1
  11. package/dist/cli.d.ts +1 -1
  12. package/dist/cli.d.ts.map +1 -1
  13. package/dist/cli.js +5 -0
  14. package/dist/cli.js.map +1 -1
  15. package/dist/commands/blocking.d.ts +7 -4
  16. package/dist/commands/blocking.d.ts.map +1 -1
  17. package/dist/commands/blocking.js +116 -40
  18. package/dist/commands/blocking.js.map +1 -1
  19. package/dist/commands/check.d.ts +10 -0
  20. package/dist/commands/check.d.ts.map +1 -1
  21. package/dist/commands/check.js +146 -33
  22. package/dist/commands/check.js.map +1 -1
  23. package/dist/commands/common.d.ts +4 -2
  24. package/dist/commands/common.d.ts.map +1 -1
  25. package/dist/commands/common.js +4 -2
  26. package/dist/commands/common.js.map +1 -1
  27. package/dist/commands/init.d.ts.map +1 -1
  28. package/dist/commands/init.js +105 -165
  29. package/dist/commands/init.js.map +1 -1
  30. package/dist/commands/keys.d.ts +6 -0
  31. package/dist/commands/keys.d.ts.map +1 -0
  32. package/dist/commands/keys.js +72 -0
  33. package/dist/commands/keys.js.map +1 -0
  34. package/dist/commands/next.d.ts.map +1 -1
  35. package/dist/commands/next.js +23 -21
  36. package/dist/commands/next.js.map +1 -1
  37. package/dist/commands/pre-commit.d.ts.map +1 -1
  38. package/dist/commands/pre-commit.js +21 -8
  39. package/dist/commands/pre-commit.js.map +1 -1
  40. package/dist/commands/test-gates.d.ts +12 -4
  41. package/dist/commands/test-gates.d.ts.map +1 -1
  42. package/dist/commands/test-gates.js +357 -75
  43. package/dist/commands/test-gates.js.map +1 -1
  44. package/dist/commands/tests.d.ts +1 -1
  45. package/dist/commands/tests.d.ts.map +1 -1
  46. package/dist/commands/tests.js +37 -3
  47. package/dist/commands/tests.js.map +1 -1
  48. package/dist/docs-exclusions.d.ts +12 -0
  49. package/dist/docs-exclusions.d.ts.map +1 -0
  50. package/dist/docs-exclusions.js +211 -0
  51. package/dist/docs-exclusions.js.map +1 -0
  52. package/dist/evaluate.d.ts +8 -12
  53. package/dist/evaluate.d.ts.map +1 -1
  54. package/dist/evaluate.js +53 -11
  55. package/dist/evaluate.js.map +1 -1
  56. package/dist/execution.d.ts +7 -3
  57. package/dist/execution.d.ts.map +1 -1
  58. package/dist/execution.js +9 -2
  59. package/dist/execution.js.map +1 -1
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +1 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/input-snapshot.d.ts +30 -6
  65. package/dist/input-snapshot.d.ts.map +1 -1
  66. package/dist/input-snapshot.js +58 -21
  67. package/dist/input-snapshot.js.map +1 -1
  68. package/dist/mapping.d.ts +18 -30
  69. package/dist/mapping.d.ts.map +1 -1
  70. package/dist/mapping.js +75 -51
  71. package/dist/mapping.js.map +1 -1
  72. package/dist/package-compatibility.d.ts +27 -0
  73. package/dist/package-compatibility.d.ts.map +1 -0
  74. package/dist/package-compatibility.js +112 -0
  75. package/dist/package-compatibility.js.map +1 -0
  76. package/dist/receipts.d.ts +13 -2
  77. package/dist/receipts.d.ts.map +1 -1
  78. package/dist/receipts.js +58 -4
  79. package/dist/receipts.js.map +1 -1
  80. package/dist/runtime-reuse.d.ts +24 -0
  81. package/dist/runtime-reuse.d.ts.map +1 -0
  82. package/dist/runtime-reuse.js +168 -0
  83. package/dist/runtime-reuse.js.map +1 -0
  84. package/dist/runtime.d.ts +2 -0
  85. package/dist/runtime.d.ts.map +1 -1
  86. package/dist/runtime.js +118 -108
  87. package/dist/runtime.js.map +1 -1
  88. package/dist/staged-candidate.d.ts +4 -0
  89. package/dist/staged-candidate.d.ts.map +1 -1
  90. package/dist/staged-candidate.js +57 -11
  91. package/dist/staged-candidate.js.map +1 -1
  92. package/dist/state.d.ts +3 -0
  93. package/dist/state.d.ts.map +1 -1
  94. package/dist/state.js +4 -0
  95. package/dist/state.js.map +1 -1
  96. package/dist/verifier-keys.d.ts +59 -0
  97. package/dist/verifier-keys.d.ts.map +1 -0
  98. package/dist/verifier-keys.js +339 -0
  99. package/dist/verifier-keys.js.map +1 -0
  100. package/guides/QUICKSTART.md +169 -0
  101. package/guides/TEST-ENVIRONMENT.md +191 -0
  102. package/guides/UPGRADE-0.6-to-0.7.md +65 -0
  103. package/package.json +14 -10
@@ -0,0 +1,191 @@
1
+ # Test environment
2
+
3
+ **Gateforge does not build the test environment.** It does not create databases, seed data, logins, or services. Your team or agent builds and resets them. This guide lists what Gateforge needs from that environment.
4
+
5
+ ## Use an isolated, disposable stack
6
+
7
+ **Rule:** Use separate test containers, network, and volumes. Never point a witnessed run at staging or production.
8
+
9
+ **Why:** Tests create and change data. A shared or live target can leak test data or let one run affect another.
10
+
11
+ **Example:** Give the test stack its own Compose project name, such as `gateforge-test`, and its own database volume.
12
+
13
+ ## Reset and seed before every run
14
+
15
+ **Rule:** Reset to a known baseline before every run. Restore a baseline dump or run a seed script from the same checkout being tested.
16
+
17
+ **Why:** Old data makes outcomes depend on run order or another developer's test.
18
+
19
+ **Example:** `reset disposable database -> seed from this checkout -> run tests`.
20
+
21
+ ## Create login state against the app
22
+
23
+ **Rule:** Mint the Playwright login state by connecting directly to the app, not through the witness proxy. Reuse one session file instead of repeatedly logging in. Set `GATEFORGE_SESSION_STATE` to that file for the supervised run.
24
+
25
+ **Why:** The witness must bind a run context before it observes traffic. Once the proxy has observed traffic, binding a new run is refused. Repeated login attempts can also hit rate limits.
26
+
27
+ **Example:** Create `.cache/gateforge-session.json` against `http://app.example.test`, then set `GATEFORGE_SESSION_STATE=.cache/gateforge-session.json`.
28
+
29
+ ## Run containers as your user
30
+
31
+ **Rule:** Give containers your user and group IDs.
32
+
33
+ **Why:** Root-owned auth or key files can become unreadable to your account. Git may also report dubious ownership.
34
+
35
+ **Example:**
36
+
37
+ ```sh
38
+ docker compose run --user "$(id -u):$(id -g)" app
39
+ ```
40
+
41
+ Replace `app` with the service in your Compose file.
42
+
43
+ ## Keep the repository unchanged during a run
44
+
45
+ **Rule:** Do not mount a different environment file over a tracked file or create temporary symlinks in the repository. Ignored files count too. Precompile first, or set `PYTHONDONTWRITEBYTECODE=1`; warm caches before the run.
46
+
47
+ **Why:** The candidate must stay the same from test planning through receipt verification. A changed or newly written cache can stale the receipt even when Git does not show it by default.
48
+
49
+ **Example:** Set `PYTHONDONTWRITEBYTECODE=1` before Python tests. Prewarm `.pytest_cache` before sealing a run, or configure the tool not to write it.
50
+
51
+ ## Make hooks repeatable
52
+
53
+ **Rule:** Hooks must not rewrite ignored files on each run, such as a linter cache. Run the full hook list twice and compare a stable tree ID before and after.
54
+
55
+ **Why:** A hook that changes its own inputs makes repeated checks non-reproducible.
56
+
57
+ **Example:** This Linux example hashes repository files, including ignored files, but excludes Git's internal directory:
58
+
59
+ ```bash
60
+ tree_id() {
61
+ tar --sort=name --exclude=./.git --mtime='@0' --owner=0 --group=0 --numeric-owner -cf - . | sha256sum
62
+ }
63
+ before="$(tree_id)"
64
+ # Run the full hook list.
65
+ # Run the full hook list again.
66
+ test "$before" = "$(tree_id)"
67
+ ```
68
+
69
+ The final comparison must pass. If it fails, find and disable or prewarm the writer before the witnessed run.
70
+
71
+ ## Sync a private Git copy
72
+
73
+ **Rule:** If the runner uses a private copy of `.git`, sync both refs and the index before every run.
74
+
75
+ **Why:** A copied checkout with stale refs or a stale index can calculate a different changed-file set than the working repository.
76
+
77
+ **Example:** Before invoking the runner, copy the current branch refs and staged index into its private Git directory.
78
+
79
+ ## Keep the harness in a durable place
80
+
81
+ **Rule:** Store the harness in this repository or a shared tools repository, not in `/tmp`.
82
+
83
+ **Why:** Temporary directories can be wiped on reboot and are not reproducible by teammates or CI.
84
+
85
+ **Example:** Keep reset, seed, and test-run scripts under a tracked `tools/` directory.
86
+
87
+ ## Keep the verifier key outside the repository
88
+
89
+ **Rule:** Use a current-user-only key ring outside the repository and run-state folder, with mode `0600` or stricter. CI can use a protected secret instead. Never put key material in the state folder.
90
+
91
+ **Why:** The key signs trusted evidence. A repository file or run artifact is writable by the candidate and cannot be a safe secret store.
92
+
93
+ **Example:**
94
+
95
+ ```sh
96
+ mkdir -p "$HOME/.config/gateforge"
97
+ gateforge key create --file "$HOME/.config/gateforge/keys.json" --confirm
98
+ export GATEFORGE_WITNESS_VERIFIER_KEY_FILE="$HOME/.config/gateforge/keys.json"
99
+ ```
100
+
101
+ The CLI does not print the secret. Keep backups private too.
102
+
103
+ ## Register the same tests in every mode
104
+
105
+ **Rule:** Register the same test set in discovery and witnessed modes. Only the witnessed test body may depend on `GATEFORGE_*` environment variables.
106
+
107
+ **Why:** If environment checks hide tests from the planned suite, the witness sees planned tests that did not execute and refuses the receipt.
108
+
109
+ **Example:** Do not wrap a whole `test()` declaration in `if (process.env.GATEFORGE_WITNESS_URL)`. Keep the test registered and put mode-specific setup inside the body.
110
+
111
+ ## Declare claims before the gate
112
+
113
+ **Rule:** Put claims in the tracked `.gateforge/test-map.yml` when `check` must know them without listing the suite.
114
+
115
+ **Why:** Hooks and CI run `check`; they do not enumerate the test suite to discover annotations. A declaration in the map is visible before test execution.
116
+
117
+ **Example:** Use `gateforge tests mark` to write the entry, then commit `.gateforge/test-map.yml` with the test changes.
118
+
119
+ ## Set the changed-file base in CI
120
+
121
+ **Rule:** Set `changed.provider` to `auto` or the intended CI provider, and provide that provider's base reference.
122
+
123
+ **Why:** Without the correct diff base, `--changed` can select no files or the wrong files. `auto` uses `GITHUB_BASE_REF` on GitHub Actions, `CI_MERGE_REQUEST_DIFF_BASE_SHA` on GitLab merge requests, and otherwise the local staged diff.
124
+
125
+ **Example:**
126
+
127
+ ```yaml
128
+ changed:
129
+ provider: auto
130
+ ```
131
+
132
+ For a GitHub Actions pull request, set `GITHUB_BASE_REF`. For a GitLab merge request, set `CI_MERGE_REQUEST_DIFF_BASE_SHA`.
133
+
134
+ ## Keep the runner quiet
135
+
136
+ **Rule:** Keep concurrent work below the machine's CPU count. Prefer a quiet runner for witnessed tests.
137
+
138
+ **Why:** Heavy parallel jobs compete with the app and browser and can cause timeouts.
139
+
140
+ **Example:** Run one changed slice at a time on a small CI runner.
141
+
142
+ ## Verify service names and fallbacks
143
+
144
+ **Rule:** App, database, and worker names or aliases must resolve inside the container network. Read service logs and check for silent fallbacks.
145
+
146
+ **Why:** A service can appear healthy while the app falls back to a local database, default credentials, or a different endpoint.
147
+
148
+ **Example:** From the app container, verify the configured database hostname resolves, then inspect the app log for its selected database URL.
149
+
150
+ ## Start with a small changed slice
151
+
152
+ **Rule:** Start with `--changed`; a full run can take much longer. Use `--result-only` to inspect selected test results when unrelated existing debt blocks the full gate.
153
+
154
+ **Why:** A small slice shortens feedback. Result-only reports results but cannot authorize a gate receipt.
155
+
156
+ **Example:**
157
+
158
+ ```sh
159
+ gateforge test-gates --changed --scope changed --result-only
160
+ ```
161
+
162
+ For an authoritative run, use `gateforge test-gates --changed` without `--result-only`, then run `gateforge check --changed --require-e2e` on the same inputs.
163
+
164
+ ## Write witnessed tests for observable behavior
165
+
166
+ **Rule:** Read a response body only when the app itself reads it. Use a random token in unique names. Anchor only fields the configured adapter exposes. Use one update anchor per entity. Wait for the page's own requests to finish before typing into a form that refetches data.
167
+
168
+ **Why:** Extra response reads can leave Playwright waiting. Reused names collide with seeded data. Unavailable or duplicate anchors cannot be independently checked. Typing before a refetch finishes can target stale UI.
169
+
170
+ **Example:** Use a unique name such as `profile-${randomToken}`, wait for the form's data request, then enter only adapter-supported fields.
171
+
172
+ ## Reusable run script
173
+
174
+ Replace the reset and seed comments with durable commands for your disposable stack. The seed must come from this checkout. `test-gates` starts and supervises the witness for the run.
175
+
176
+ ```bash
177
+ #!/usr/bin/env bash
178
+ set -euo pipefail
179
+
180
+ # Reset the disposable database from a baseline dump or reset script.
181
+ # <your reset command>
182
+
183
+ # Seed it from this checkout.
184
+ # <your seed command>
185
+
186
+ # Start the supervised witnessed run and seal a receipt on complete success.
187
+ gateforge test-gates --changed
188
+
189
+ # Check the same changed inputs against that receipt.
190
+ gateforge check --changed --require-e2e
191
+ ```
@@ -0,0 +1,65 @@
1
+ # Upgrade from 0.6 to 0.7
2
+
3
+ ## Upgrade steps
4
+
5
+ 1. Set every direct `@gate-forge/*` dependency to `0.7.1`. Update any wrapper script, CI image, or install command that pins an older CLI version. The CLI checks the supervised Playwright contract; an incompatible package set exits 2 with `GATEFORGE_PACKAGE_INCOMPATIBLE`.
6
+
7
+ Example package set:
8
+
9
+ ```sh
10
+ npm i -D \
11
+ @gate-forge/cli@0.7.1 \
12
+ @gate-forge/pack-playwright@0.7.1 \
13
+ @gate-forge/pack-http@0.7.1 \
14
+ @gate-forge/pack-fastapi@0.7.1 \
15
+ @gate-forge/pack-sqlalchemy@0.7.1
16
+ ```
17
+
18
+ 2. Install the updated lockfile:
19
+
20
+ ```sh
21
+ npm install
22
+ ```
23
+
24
+ 3. Keep the verifier key in a protected environment variable or an external key ring. For example, create a current-user-owned key ring outside the repository and state directory:
25
+
26
+ ```sh
27
+ mkdir -p "$HOME/.config/gateforge"
28
+ gateforge key create --file "$HOME/.config/gateforge/keys.json" --confirm
29
+ export GATEFORGE_WITNESS_VERIFIER_KEY_FILE="$HOME/.config/gateforge/keys.json"
30
+ ```
31
+
32
+ 4. Run the suite under Gateforge after upgrading:
33
+
34
+ ```sh
35
+ gateforge test-gates --changed
36
+ ```
37
+
38
+ This supervised run records the current claim inventory in its authenticated receipt. A leftover `claims.json` is not a declaration source. Keep annotation-only claims in `.gateforge/test-map.yml` when hooks or CI must see them before a suite runs.
39
+
40
+ 5. Check the same candidate bytes:
41
+
42
+ ```sh
43
+ gateforge check --changed --require-e2e
44
+ ```
45
+
46
+ If you edit an input after the witnessed run, run the suite again before checking.
47
+
48
+ ## Behavior changes in 0.7.0
49
+
50
+ - **Claim inventory:** `check` no longer trusts a leftover `claims.json`. Annotations are collected for the current supervised run and authenticated in its receipt. A tracked `.gateforge/test-map.yml` makes claims available to a static check without running or listing the suite.
51
+ - **External key ring:** `gateforge key create`, `import-env`, `rotate`, and `retire` manage keys outside the repository. The key file must be a regular file owned by the current user, mode `0600` or stricter, and outside run state. CI may instead provide the protected key environment variable.
52
+ - **Documentation exclusions:** Input hashing includes files by default. An explicit docs-only exclusion is written to `.gateforge/docs-exclusions.yml` and stays inactive until its policy digest is approved in protected CI settings. For example, `gateforge init --docs-exclude docs,handbook` selects folders; review the generated policy before enabling it.
53
+ - **Result-only runs:** `gateforge test-gates --changed --scope changed --result-only` reports a changed slice and repository debt but has no gate authority and does not create, replace, or clear a receipt.
54
+ - **External-witness result-only:** The same result-only mode accepts `--witness-url`, `--out`, and `--run-token`. Use a dedicated state directory separate from `.gateforge/test-gates`; an external-witness result does not become an authoritative receipt.
55
+ - **Surface diagnostic:** `gateforge tests surface-doctor` lists Playwright tests that need a UI surface descriptor.
56
+ - **Runner context:** The supervised Playwright runner passes the configured app base URL and `GATEFORGE_SESSION_STATE` as trusted `baseURL` and `storageState` settings.
57
+
58
+ ## If something breaks
59
+
60
+ | If you see | Do this |
61
+ |---|---|
62
+ | `GATEFORGE_PACKAGE_INCOMPATIBLE` | Align direct Gateforge packages to `0.7.1`, update wrapper pins, then run `npm install`. |
63
+ | `EVIDENCE_STALE` or `RUN_INCOMPLETE` | Run `gateforge test-gates --changed` on the exact candidate, then check again. |
64
+ | A missing or stale test mapping | Run `gateforge tests discover`, then inspect `gateforge tests suggest`; declare a valid existing test in `.gateforge/test-map.yml`. |
65
+ | Tests are missing a UI surface | Run `gateforge tests surface-doctor` and add the required descriptor. |
package/package.json CHANGED
@@ -1,6 +1,9 @@
1
1
  {
2
2
  "name": "@gate-forge/cli",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
+ "gateforgeCompatibility": {
5
+ "supervisedFixtureProtocol": "gateforge.supervised-playwright.v1"
6
+ },
4
7
  "license": "Apache-2.0",
5
8
  "description": "Gateforge CLI: init, discover, obligations, check, test-gates, baseline update.",
6
9
  "type": "module",
@@ -18,7 +21,8 @@
18
21
  },
19
22
  "files": [
20
23
  "bin",
21
- "dist"
24
+ "dist",
25
+ "guides"
22
26
  ],
23
27
  "scripts": {
24
28
  "build": "tsc -p tsconfig.build.json",
@@ -27,14 +31,14 @@
27
31
  "test": "vitest run"
28
32
  },
29
33
  "dependencies": {
30
- "@gate-forge/core": "^0.6.3",
31
- "@gate-forge/http-contract": "^0.6.3",
32
- "@gate-forge/pack-fastapi": "^0.6.3",
33
- "@gate-forge/pack-http": "^0.6.3",
34
- "@gate-forge/pack-playwright": "^0.6.3",
35
- "@gate-forge/pack-sqlalchemy": "^0.6.3",
36
- "@gate-forge/pack-task": "^0.6.3",
37
- "@gate-forge/plugin-protocol": "^0.6.3",
34
+ "@gate-forge/core": "^0.7.1",
35
+ "@gate-forge/http-contract": "^0.7.1",
36
+ "@gate-forge/pack-fastapi": "^0.7.1",
37
+ "@gate-forge/pack-http": "^0.7.1",
38
+ "@gate-forge/pack-playwright": "^0.7.1",
39
+ "@gate-forge/pack-sqlalchemy": "^0.7.1",
40
+ "@gate-forge/pack-task": "^0.7.1",
41
+ "@gate-forge/plugin-protocol": "^0.7.1",
38
42
  "picomatch": "^4.0.7",
39
43
  "yaml": "^2.8.1"
40
44
  },