You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7931f81
Browse filesBrowse the repository at this point in the historyBrowse files
feat(cli): os validate --target fetches the restriction profile from an environment URL (#31766)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9Y2yLH3VS5En8ea6L8PLhow)_Fixes#31240
Clause-②: no
Metadata-protocol: none
Route: the seat ruled (step 0, option B) that this cloud route needs no
spec route ledger entry: the ledger records the routes this repository's
runtime serves, and the CLI only reads this one as a client.
`domain:server#3` · dev session `session_01ADHkmSfgXVignEEbsJjzMa`
## 维护者速读
- 改了什么:`os validate --target` 除了本地 profile 文件,现在也接受环境的 http(s) URL:从该
URL 的 origin 取 `GET /api/v1/discovery/restriction-profile`,按 `{ success,
data }` 读出,`data` 用 `RestrictionProfileSchema` 解析,判定和文件形式完全一致。
- 为什么改:卡 #31240,cloud PR #3732 已合入并发布该路由,作者不必再先把 profile 存成文件。
- 风险与回滚:无法访问、超时、非 2xx(含 404 RESOURCE_NOT_FOUND)、非 JSON、信封不对、schema
不合法,一律拒绝并点名 URL,绝不当成「没有限制」。文件形式不变。回滚即还原本 PR。
- 先看:`packages/cli/src/utils/restriction-profile.ts` 的
`fetchRestrictionProfile` 与
`RESTRICTION_PROFILE_ROUTE`;`packages/cli/src/commands/validate.ts` 第 0
步改成 `await`。
- 两分钟验证:`pnpm --filter @objectstack/cli exec vitest run
src/utils/restriction-profile.test.ts
test/validate-target-restriction-profile.test.ts`,预期 58 条全绿。
- 需要你做的:无,席位落地。
## What changes
**Step 0 (read-only, `origin/main` 0105a68).**
| Check | Reading |
|:--|:--|
| `discovery/restriction-profile` in the spec route surface
(`packages/spec/src/api`) and the runtime route ledger
(`packages/runtime/src/route-ledger.ts`) | 0 hits (`git grep -c
restriction-profile`, exit 1). Control: the same trees name
`/api/v1/discovery` (`dispatcher.zod.ts:103`,
`plugin-rest-api.zod.ts:817`, `route-ledger.ts:248`). Seat ruling B
above: no spec entry is owed. |
| `loadRestrictionProfile` on `main` | any `scheme://` target refused
(`isUrl`) with "no defined address yet, save it as a JSON file"; then
file missing / not JSON / schema-invalid each refused. Synchronous. |
| `validate.ts` step 0 on `main` | calls the loader first, before the
stack is loaded; prints `Target profile` with the file path. |
**The route.** `RESTRICTION_PROFILE_ROUTE =
'/api/v1/discovery/restriction-profile'`, named once in
`restriction-profile.ts`. Its source is cloud PR
objectstack-ai/cloud#3732 (cloud#3713), with the shape recorded on this
card in comment 6716619631: `GET`, no auth, a `{ success, data }` body,
`404 RESOURCE_NOT_FOUND` when the host names no environment, `503`
otherwise. The code comment beside the constant cites both.
**The URL form.** `loadRestrictionProfile(target, cwd)` is now `async`
and returns `{ profile, source }` (`source` = the file read or the URL
fetched; it was `file`). For a `scheme://` target:
- only `http:` / `https:` are fetched; any other scheme is refused
before a request, naming the file form as the remedy;
- the profile is fetched from `RESTRICTION_PROFILE_ROUTE` at the
target's **origin** (a path, query or hash on the target is not used),
with `accept: application/json` and a 15 s timeout;
- the body must be JSON and the `{ success: true, data }` envelope,
checked locally (no new spec schema is exported); `data` is parsed with
`RestrictionProfileSchema`, the same parse as the file form; schema
issues are named under `data.`;
- every failure is refused, naming the URL fetched: unreachable or timed
out, any non-2xx (the envelope's `error.code` is named when present; a
404 adds "no environment is served at this host"), non-JSON, wrong
envelope, schema-invalid. None is read as "no restriction".
The file branch is unchanged except for the shared issue formatter
(`profileIssues`), which prints the same text it printed before.
`validate.ts` awaits the loader, prints `source`, and the `--target`
flag help names the URL form.
## Tests
`src/utils/restriction-profile.test.ts`, new
`describe('loadRestrictionProfile — an environment URL')` against a
local `node:http` stub on `127.0.0.1:0` (never a real environment), 8
cases:
- parity: the stub serves a Team-shaped profile; the fetched profile
equals the same content read from a file, the stub saw exactly one `GET
/api/v1/discovery/restriction-profile` (target given with a path and
query, so the origin rule is pinned), `source` is the route URL, and
`judgeRestrictionProfile` returns the same rows for both;
- refused, each naming the URL: 404 `RESOURCE_NOT_FOUND`, 503, a 200
that is not JSON, JSON outside the envelope (bare profile; `success:
false`), schema-invalid `data` (`data.allowCode`; and `{}`), a closed
port (`ECONNREFUSED`);
- a `file://` target is refused naming the file form, and the stub saw
no request.
`test/validate-target-restriction-profile.test.ts`, new `describe('os
validate --target ENV_URL')`, 6 cases through `Command.run`: the same
exit, `valid` and `errors` rows for an open and an `allowCode: false`
profile from a URL as from a file; the text face prints the fetched URL;
a 404, a non-JSON and a schema-invalid answer, and an unreachable
environment, each exit 1 with `valid: false` and an `error` naming the
URL.
Forced test changes:
- `src/utils/restriction-profile.test.ts`, the four existing file-form
cases: `await` / `.rejects.toThrow` because the loader is now async.
Their inputs and expected text are unchanged (CONTROL).
- `src/utils/restriction-profile.test.ts`, `refuses a URL rather than
fetching from a guessed route`: removed, the behaviour this card
replaces. Its successor is the `file://` case above.
- `test/validate-target-restriction-profile.test.ts`, `a URL target is
refused, naming the file form as the remedy`: now feeds a `file://` URL
(an `https://` one is fetched now); same assertion on the remedy, plus
`valid: false`.
**Ablation (fail-open).** With the fix committed,
`scripts/ablation-replace.mjs` replaced the URL branch with one that
turns any fetch failure into an all-open profile (marker
`ABLATION_31240_FAIL_OPEN`; anchor 1 → 0, blob `1049b5a2cabe` →
`13828918c01d`). Both files: `Tests 12 failed | 46 passed (58)`; the 12
are exactly the refusal cases: the 7 unit ones and the 5 command-level
ones (the `file://` case included). The parity cases stay green, as they
should. Restored with `git checkout HEAD -- …`; `git diff HEAD` 0 bytes,
marker count 0.
<details><summary>Ablation excerpt</summary>
```text
FAIL |unit| src/utils/restriction-profile.test.ts > loadRestrictionProfile — an environment URL > refuses a 404 RESOURCE_NOT_FOUND (the host names no environment), naming the URL
AssertionError: promise resolved "{ …(2) }" instead of rejecting
FAIL |unit| test/validate-target-restriction-profile.test.ts > os validate --target ENV_URL > an environment it cannot reach is refused, naming the URL
: expected +0 to be 1 // Object.is equality
Test Files 2 failed (2)
Tests 12 failed | 46 passed (58)
```
</details>
## Acceptance notes
- The URL form uses the target's origin only. An environment served
under a path prefix is not a shape the cloud route describes
(`ENV_ORIGIN/api/v1/...`), so none is guessed.
- No auth header is sent: the route is unauthenticated per comment
6716619631.
## Verification
All on head `221901c7` (the last commit), worktree of this branch.
- `pnpm --filter @objectstack/cli exec vitest run
src/utils/restriction-profile.test.ts
test/validate-target-restriction-profile.test.ts`: `Test Files 2 passed
(2) · Tests 58 passed (58)`, lock VERDICT command-exit 0.
- cli unit tier `pnpm --filter @objectstack/cli exec vitest run
--project unit --maxWorkers=2`: `Test Files 2 failed | 405 passed (407)
· Tests 5759 passed | 29 skipped`. The two failed files
(`published-subpath-console.pin`, `published-subpath-hook-body.pin`)
refused at collection because `packages/cli/dist` was not built yet
("packages/cli is not built … Run: pnpm --filter @objectstack/cli
build"). After the build: `Test Files 2 passed (2) · Tests 29 passed
(29)`. The integration tier is declared to CI (no spawn entry or
integration file touched).
- `pnpm --filter @objectstack/cli typecheck`: exit 0 (test layer:
`check:test-typecheck: OK`, debt unchanged).
- Lint: `@objectstack/cli` has no `lint` script; `pnpm exec eslint
--no-inline-config packages/cli`: exit 0.
- Derived gates: `node scripts/pm/dispatch-gates.mjs --commands` named
66 families; all 66 exit 0. Five first answered exit 3 (prerequisite,
nothing measured): `check-plugin-teardown-shape --self-test` (fixture
commit not fetched) and `check:dual-build-cjs-loads`, `check:i18n`,
`check:i18n-coverage`, `check:i18n-walk-parity` (workspace not built).
Each re-ran green after the fetch and `turbo run build
--filter='./packages/**' --filter='./examples/**'`. `--ran`
reconciliation: `66 derived, 66 run, 0 NOT-MEASURED, 0 UNRUN`.
- Dogfood: not run (no `!` in the title, no `(narrowing)` arm).
- CI families: see this PR's check-runs.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmSfgXVignEEbsJjzMa)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
`os validate --target` now also takes an environment's `http://` or `https://` URL. The command fetches `GET /api/v1/discovery/restriction-profile` at that URL's origin (the route a hosted environment publishes its profile at), reads the `{ success, data }` body and parses `data` with `RestrictionProfileSchema`, the same parse the file form uses, so a fetched profile judges the stack exactly as the same profile saved to a file.
11
+
12
+
Every failure is refused and names the URL fetched: an environment that cannot be reached or does not answer within 15 seconds, any non-2xx answer (a `404 RESOURCE_NOT_FOUND` means no environment is served at that host), a body that is not JSON or not the `{ success: true, data }` envelope, and a profile the schema rejects. None of them is ever judged as "no restriction". A URL with any other scheme is refused before anything is fetched. The file form is unchanged.
0 commit comments