Skip to content

Commit f7c95cd

Browse files
test(dogfood): pin five api-backend checklist items at the HTTP layer (#26787)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8VsCYkn9rw8Z1i5vq5MHxL4)_ Refs #26572 (slice 1 of about 3: items declarative-endpoint-execution, second-object-exposure-and-internal-fields, data-request-shape-and-query-arity, meta-read-doors-v18, error-sentences-and-unique-violation-wire-code) Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:给 api-backend 清单里 5 个被 18.2.0 Tier 1 扫描判为 PARTIAL 的条目补上 HTTP 层(真实 Hono 栈)的 dogfood 钉子,并把这 5 条的 automated.ref、verify 文本、revision 和 history 更新。 - 为什么改:这些条款的判据在 HTTP 或构建层,旧钉子只到单元/引擎层,每次发版扫描都要人工再跑活腿;现在变成常驻、可重跑的证明。 - 风险与回滚:只加测试和清单文本,不改任何产品代码;回滚就是 revert 本 PR。dogfood 只在 main 的定时/推送批次跑,不进 PR 和合并队列。 - 先看:`packages/qa/dogfood/test/declarative-endpoint-authoring-refusal.dogfood.test.ts`(子进程跑 CLI)、`packages/qa/dogfood/test/fixtures/second-object-exposure-fixture.ts`(共享 fixture 加了一个 internal 字段)、`docs/qa/platform-checklist/areas/api-backend.json`。 - 两分钟验证:`pnpm --filter @objectstack/dogfood exec vitest run --maxWorkers=2 test/data-request-shape-live.dogfood.test.ts`,预期 13 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes Five api-backend checklist items that the release-18.2.0 Tier 1 sweep (#26468) scored PARTIAL now carry pins at the layer their oracle names. Every new case drives a booted stack through `@objectstack/verify`'s real HTTP surface (Hono request injection), or the CLI's own `bin/run.js` as a child process for the one `build` oracle. | Item | Clauses pinned | Pin | |---|---|---| | `api-backend.declarative-endpoint-execution` | acceptance[1] (401 `UNAUTHENTICATED` code), acceptance[2] (`os validate` / `os build` refuse a script and a proxy endpoint, naming it, the type and the flow prescription, no artifact; the #5488 withdrawal: `PUT /meta/api/NAME` answers 403 `NOT_CREATABLE`) | `showcase-declarative-endpoints.dogfood.test.ts` (extended), `declarative-endpoint-authoring-refusal.dogfood.test.ts` (new) | | `api-backend.second-object-exposure-and-internal-fields` | acceptance[1] (refusal located at `filter.REL` on both doors), acceptance[3] (an `internal: true` field refused 400 `INVALID_FIELD` naming object and field in filter, sort, groupBy and aggregate positions) | `second-object-exposure.dogfood.test.ts` (extended); its fixture gains `sox_source.internal_f` | | `api-backend.data-request-shape-and-query-arity` | acceptance[1]–[4] | `data-request-shape-live.dogfood.test.ts` (new) | | `api-backend.meta-read-doors-v18` | acceptance[1]–[4] (the FLS half for a `client_liaison`-bound member, both halves agreeing) | `meta-read-doors-live.dogfood.test.ts` (new) | | `api-backend.error-sentences-and-unique-violation-wire-code` | acceptance[1]–[3] | `error-sentences-live.dogfood.test.ts` + `fixtures/error-sentences-fixture.ts` (new scratch app) | Each item's `automated.ref` names the new pins and what they assert, the verify texts that said "live leg" now say which pin carries the clause, `revision` is bumped and a `history` row cites #26572. No clause text changed. No product code changed. ## Why The card's ruled scope (triage 6437722483): pin the 11 api-backend Tier 1 clauses the 18.2.0 sweep scored PARTIAL at the layer their oracle names, in `packages/qa/dogfood/**`, with the checklist item revisions bumped, in slices of about five items, with no new CI lane. This is the first slice. The other six items (packaged-action-disabled-dispatch, action-activation-door-contract, rest-crud-config-contract, rest-batch-config-contract, rest-metadata-config-contract, rest-route-generation-tombstones) are left for later slices. ## Tests All seven touched dogfood files on the final head 19a4d70, under the verify lock, after rebuilding the one package main moved since the base (`driver-sql`): ``` pnpm --filter @objectstack/dogfood exec vitest run --maxWorkers=2 test/data-request-shape-live.dogfood.test.ts test/meta-read-doors-live.dogfood.test.ts test/error-sentences-live.dogfood.test.ts test/declarative-endpoint-authoring-refusal.dogfood.test.ts test/second-object-exposure.dogfood.test.ts test/import-reference-exposure.dogfood.test.ts test/showcase-declarative-endpoints.dogfood.test.ts Test Files 7 passed (7) Tests 119 passed (119) os-verify-lock: VERDICT command-exit 0 ``` `import-reference-exposure.dogfood.test.ts` is in the run because it shares the fixture that gained a field. Every expectation was first measured against the live answer on a probe boot and checked against the clause text before it was written down. No ablation: the diff changes no tested behaviour, only adds pins over behaviour that already holds. ## Acceptance notes - Dogfood runs only in `main`'s scheduled and push battery (`Dogfood Regression Gate`'s `if:` excludes `pull_request` and `merge_group`), so the PR's CI does not run these files; the local run above is their evidence until the next `main` battery. - The CLI pin writes its scratch config through `defineStack(…, { strict: false })` with `@objectstack/spec` linked into a temporary `node_modules`: the commands accept only a stack `defineStack` returned, and the strict factory would refuse the endpoint at import, before the command's own gate. - The located position of a nested-relation refusal lives only in the refusal sentence (`… at 'filter.REL' …`); the pin asserts that token, the code, the status and `object`. - The storage fault is forced by putting the local adapter's root under a regular file, so the write fails with `ENOTDIR`; the pin asserts `500 INTERNAL` and that neither the errno, the path nor a stack line reaches the body. ## Verification <details><summary>Gates (dispatch-gates --commands, reconciled with --ran)</summary> - `node scripts/check-platform-checklist.mjs`: exit 0, `OK — 16 areas, 329 items (324 active, 1 planned)`. - 55 derived commands: 53 exit 0; 2 exit 3 (prerequisite not met, nothing measured): `node scripts/check-plugin-teardown-shape.mjs --self-test` (its positive control is pinned to a commit outside this shallow clone) and `pnpm check:dual-build-cjs-loads` (reads built output of packages outside the dogfood closure). Both run in CI's `Lint & Repo Gates`. - `pnpm --filter @objectstack/dogfood run typecheck`: exit 0. - eslint over the eight touched TypeScript files: exit 0. - `dispatch-gates --ran`: 55 derived families accounted for, 53 run, 2 NOT-MEASURED, 0 unrun. </details> No changeset: `@objectstack/dogfood` is private and `docs/qa/**` ships in no package, so this PR carries `skip-changeset`. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. (eslint over the touched files) - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset. (nothing publishes) - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbWUpGqdpDRiD79LqXV --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbWUpGqdpDRiD79LqXV)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 83c4bd2 commit f7c95cd

9 files changed

Lines changed: 845 additions & 23 deletions

‎docs/qa/platform-checklist/areas/api-backend.json‎

Lines changed: 52 additions & 22 deletions
Large diffs are not rendered by default.
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// [#26572] `api-backend.data-request-shape-and-query-arity` acceptance[1]–[4]
4+
// over the real HTTP stack of a booted showcase. Every pin the item named
5+
// before this file called the RestServer handlers or `HttpDispatcher.dispatch()`
6+
// directly and none booted the Hono adapter, so each `api` clause scored
7+
// partial. These are the item's own steps, driven through the door a client
8+
// reaches:
9+
//
10+
// - PATCH /data/showcase_task/ID with a `null`, `[]` or `5` body, a body
11+
// `expectedVersion` of '' and an empty `If-Match`: 400 VALIDATION_FAILED,
12+
// and the row's `updated_at` (its version) unchanged.
13+
// - POST /data/showcase_task/query with a `null` body: 400, no rows.
14+
// - GET /packages?status=a&status=b and the doubled-`keepData` DELETE of the
15+
// showcase package: 400 VALIDATION_ERROR naming the count, and the package
16+
// and its tables still answer afterwards (this boot is this file's own, so
17+
// the destructive probe runs on a throwaway stack).
18+
// - A member's PATCH with a stale If-Match on an admin-owned
19+
// `showcase_private_note` (owner-private OWD): 404, byte-identical to the
20+
// same PATCH with no token — never a 409 carrying `currentRecord`. The
21+
// admin's stale PATCH on the same row is the positive CONTROL: a 409.
22+
//
23+
// Codes and statuses are asserted; refusal prose only where the clause names
24+
// it ("supplied N times").
25+
26+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
27+
import { type VerifyStack } from '@objectstack/verify';
28+
import { bootShowcase } from './showcase-boot.js';
29+
import { showcaseAppDefaultSecurity } from './showcase-security.js';
30+
31+
const TASK = 'showcase_task';
32+
const NOTE = 'showcase_private_note';
33+
const PKG = 'com.example.showcase';
34+
const STALE = '2000-01-01T00:00:00.000Z';
35+
const SECRET = 'drs-live-note-body-26572';
36+
37+
const idOf = (b: any): string => String(b?.id ?? b?.record?.id ?? b?.data?.id ?? '');
38+
const codeOf = (b: any): string | undefined => (b?.error && typeof b.error === 'object' ? b.error.code : b?.code);
39+
const recordsOf = (b: any): unknown[] | undefined => b?.records ?? b?.data?.records;
40+
41+
describe('[#26572] /data request-shape gates and dispatcher query arity, over HTTP on a booted showcase', () => {
42+
let stack: VerifyStack;
43+
let admin = '';
44+
let member = '';
45+
let taskId = '';
46+
let noteId = '';
47+
48+
const withHeaders = (token: string, method: string, path: string, headers: Record<string, string>, body: unknown) =>
49+
stack.api(path, {
50+
method,
51+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}`, ...headers },
52+
body: JSON.stringify(body),
53+
});
54+
55+
const taskVersion = async (): Promise<string> => {
56+
const res = await stack.apiAs(admin, 'GET', `/data/${TASK}/${taskId}`);
57+
expect(res.status, await res.clone().text()).toBe(200);
58+
const body: any = await res.json();
59+
return String((body.record ?? body).updated_at);
60+
};
61+
62+
beforeAll(async () => {
63+
stack = await bootShowcase({ security: showcaseAppDefaultSecurity() });
64+
admin = await stack.signIn();
65+
member = await stack.signUp('drs-live-member@verify.test');
66+
// One of the showcase's seeded tasks: the step names "one showcase_task
67+
// row id and its current version token", not a row of this file's making.
68+
const tasks = await stack.apiAs(admin, 'GET', `/data/${TASK}?$top=1`);
69+
expect(tasks.status, await tasks.clone().text()).toBe(200);
70+
taskId = String((recordsOf(await tasks.json()) as any[] | undefined)?.[0]?.id ?? '');
71+
expect(taskId, 'the showcase seeds tasks').not.toBe('');
72+
const note = await stack.apiAs(admin, 'POST', `/data/${NOTE}`, { title: 'drs live note', body: SECRET });
73+
expect(note.status, await note.clone().text()).toBe(201);
74+
noteId = idOf(await note.json());
75+
}, 240_000);
76+
77+
afterAll(async () => {
78+
await stack?.stop?.();
79+
});
80+
81+
describe('acceptance[1] — a PATCH body that is not a record, or a token that can never carry a version', () => {
82+
for (const [shape, body] of [['null', null], ['an array', []], ['a number', 5]] as const) {
83+
it(`${shape} body: 400 VALIDATION_FAILED on data, updated_at unchanged`, async () => {
84+
const before = await taskVersion();
85+
const res = await stack.apiAs(admin, 'PATCH', `/data/${TASK}/${taskId}`, body);
86+
const answer: any = await res.json();
87+
expect({ status: res.status, code: codeOf(answer) }, JSON.stringify(answer)).toEqual({ status: 400, code: 'VALIDATION_FAILED' });
88+
expect((answer.fields ?? answer.error?.details?.fields ?? []).map((f: any) => f?.field)).toEqual(['data']);
89+
expect(await taskVersion()).toBe(before);
90+
});
91+
}
92+
93+
it("a body expectedVersion of '': 400 VALIDATION_FAILED, updated_at unchanged", async () => {
94+
const before = await taskVersion();
95+
const res = await stack.apiAs(admin, 'PATCH', `/data/${TASK}/${taskId}`, { title: 'drs changed', expectedVersion: '' });
96+
const answer: any = await res.json();
97+
expect({ status: res.status, code: codeOf(answer) }, JSON.stringify(answer)).toEqual({ status: 400, code: 'VALIDATION_FAILED' });
98+
expect(await taskVersion()).toBe(before);
99+
});
100+
101+
it('an empty If-Match header: 400 VALIDATION_FAILED, updated_at unchanged', async () => {
102+
const before = await taskVersion();
103+
const res = await withHeaders(admin, 'PATCH', `/data/${TASK}/${taskId}`, { 'If-Match': '' }, { title: 'drs changed' });
104+
const answer: any = await res.json();
105+
expect({ status: res.status, code: codeOf(answer) }, JSON.stringify(answer)).toEqual({ status: 400, code: 'VALIDATION_FAILED' });
106+
expect(await taskVersion()).toBe(before);
107+
});
108+
109+
it('CONTROL — a record body with the current If-Match updates the row (200) and moves its version', async () => {
110+
const before = await taskVersion();
111+
await new Promise((resolve) => setTimeout(resolve, 5));
112+
const res = await withHeaders(admin, 'PATCH', `/data/${TASK}/${taskId}`, { 'If-Match': before }, { title: 'drs live task, edited' });
113+
expect(res.status, await res.clone().text()).toBe(200);
114+
expect(await taskVersion()).not.toBe(before);
115+
});
116+
});
117+
118+
describe('acceptance[2] — a null /query body', () => {
119+
it('400 VALIDATION_FAILED on query, and no rows', async () => {
120+
const res = await stack.apiAs(admin, 'POST', `/data/${TASK}/query`, null);
121+
const answer: any = await res.json();
122+
expect({ status: res.status, code: codeOf(answer) }, JSON.stringify(answer)).toEqual({ status: 400, code: 'VALIDATION_FAILED' });
123+
expect(recordsOf(answer)).toBeUndefined();
124+
});
125+
126+
it('CONTROL — an empty query answers rows (200)', async () => {
127+
const res = await stack.apiAs(admin, 'POST', `/data/${TASK}/query`, {});
128+
expect(res.status, await res.clone().text()).toBe(200);
129+
expect((recordsOf(await res.json()) ?? []).length).toBeGreaterThan(0);
130+
});
131+
});
132+
133+
describe('acceptance[3] — a repeated single-valued query name on the dispatcher doors', () => {
134+
const expectArity = async (res: Response, name: string) => {
135+
const answer: any = await res.json();
136+
expect({ status: res.status, code: codeOf(answer) }, JSON.stringify(answer)).toEqual({ status: 400, code: 'VALIDATION_ERROR' });
137+
expect(String(answer.error?.message)).toContain(`"${name}" query parameter was supplied 2 times`);
138+
};
139+
140+
it('GET /packages?status=a&status=b: 400 VALIDATION_ERROR, supplied 2 times', async () => {
141+
await expectArity(await stack.apiAs(admin, 'GET', '/packages?status=a&status=b'), 'status');
142+
});
143+
144+
it('DELETE /packages/PKG?keepData=true&keepData=true: refused, and the package and its tables remain', async () => {
145+
await expectArity(await stack.apiAs(admin, 'DELETE', `/packages/${PKG}?keepData=true&keepData=true`), 'keepData');
146+
147+
const list = await stack.apiAs(admin, 'GET', '/packages');
148+
expect(list.status, await list.clone().text()).toBe(200);
149+
const packages: any[] = ((await list.json()) as any)?.data?.packages ?? [];
150+
expect(packages.map((p) => p?.manifest?.id)).toContain(PKG);
151+
152+
const read = await stack.apiAs(admin, 'GET', `/data/${TASK}/${taskId}`);
153+
expect(read.status, `the showcase's table still serves its rows: ${await read.clone().text()}`).toBe(200);
154+
});
155+
});
156+
157+
describe('acceptance[4] — a stale If-Match on a row the caller cannot read', () => {
158+
it('member: 404, exactly what the same PATCH with no token answers — no version, no record', async () => {
159+
const control = await stack.apiAs(member, 'PATCH', `/data/${NOTE}/${noteId}`, { body: 'drs member edit' });
160+
const controlBody: any = await control.json();
161+
expect({ status: control.status, code: codeOf(controlBody) }, JSON.stringify(controlBody)).toEqual({ status: 404, code: 'RECORD_NOT_FOUND' });
162+
163+
const stale = await withHeaders(member, 'PATCH', `/data/${NOTE}/${noteId}`, { 'If-Match': STALE }, { body: 'drs member edit' });
164+
const text = await stale.text();
165+
expect(stale.status, text).toBe(404);
166+
expect(JSON.parse(text)).toEqual(controlBody);
167+
expect(text).not.toContain('currentVersion');
168+
expect(text).not.toContain('currentRecord');
169+
expect(text).not.toContain(SECRET);
170+
});
171+
172+
it('CONTROL — the owner\'s stale If-Match on the same row is 409 CONCURRENT_UPDATE: conflict detection is not weakened', async () => {
173+
const res = await withHeaders(admin, 'PATCH', `/data/${NOTE}/${noteId}`, { 'If-Match': STALE }, { body: 'drs admin edit' });
174+
const answer: any = await res.json();
175+
expect({ status: res.status, code: codeOf(answer) }, JSON.stringify(answer)).toEqual({ status: 409, code: 'CONCURRENT_UPDATE' });
176+
});
177+
178+
it('the row is untouched by every refused write', async () => {
179+
const res = await stack.apiAs(admin, 'GET', `/data/${NOTE}/${noteId}`);
180+
const body: any = await res.json();
181+
expect((body.record ?? body).body).toBe(SECRET);
182+
});
183+
});
184+
});
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
//
3+
// [#26572] `api-backend.declarative-endpoint-execution` acceptance[2]: a
4+
// `script` / `proxy` endpoint is never served, and the refusal happens at
5+
// AUTHORING. Its oracle is the build: the item's live leg authors one of each
6+
// in a scratch config and runs `os validate` / `os build`. The pins it had
7+
// stopped a layer short of that — `apis-publish-gates.test.ts` gate (a) calls
8+
// the spec's gate directly (the script case by its fix sentence, the proxy
9+
// case by its SSRF reason, neither by the endpoint's name), and nothing
10+
// asserted that runtime authoring of `api` is withdrawn (#5488).
11+
//
12+
// So this file drives the two doors an author actually has:
13+
//
14+
// 1. The CLI, as a child process over a scratch config — the same `bin/run.js`
15+
// an author runs. `os validate` and `os build` must exit non-zero, name the
16+
// endpoint, the refused type and the `type: 'flow'` prescription, and
17+
// `os build` must write no artifact. The CONTROL is the same config with
18+
// a `flow` endpoint, which both commands accept: without it a config that
19+
// failed for an unrelated reason would read as a refusal.
20+
// 2. The metadata door of a booted showcase (#5488): `api` is code-only
21+
// (`allowRuntimeCreate: false`), so a runtime save of a well-formed `flow`
22+
// endpoint is refused and the store does not gain the item.
23+
//
24+
// The scratch config is `defineStack(…, { strict: false })` in a fresh
25+
// temporary directory, with `@objectstack/spec` linked into its
26+
// `node_modules` (the commands accept only a stack `defineStack` returned).
27+
// `strict: false` is load-bearing: the strict factory parses eagerly, so the
28+
// import itself would refuse the endpoint and the command's own gate — the
29+
// door under test — would never be consulted.
30+
31+
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
32+
import { spawnSync } from 'node:child_process';
33+
import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
34+
import { createRequire } from 'node:module';
35+
import { tmpdir } from 'node:os';
36+
import { dirname, join } from 'node:path';
37+
import { type VerifyStack } from '@objectstack/verify';
38+
import { bootShowcase } from './showcase-boot.js';
39+
import { showcaseAppDefaultSecurity } from './showcase-security.js';
40+
41+
const CLI_ROOT = dirname(createRequire(import.meta.url).resolve('@objectstack/cli/package.json'));
42+
const CLI_BIN = join(CLI_ROOT, 'bin', 'run.js');
43+
const SPEC_ROOT = dirname(createRequire(import.meta.url).resolve('@objectstack/spec/package.json'));
44+
45+
const MANIFEST = {
46+
id: 'com.dogfood.endpoint-authoring',
47+
name: 'Endpoint Authoring Probe',
48+
namespace: 'epauth',
49+
version: '1.0.0',
50+
type: 'app',
51+
};
52+
53+
const OBJECT = {
54+
name: 'epauth_note',
55+
label: 'Note',
56+
pluralLabel: 'Notes',
57+
sharingModel: 'public_read_write',
58+
fields: { name: { type: 'text', label: 'Name' } },
59+
};
60+
61+
const endpoint = (name: string, type: string, target: string) => ({
62+
name,
63+
path: `/api/v1/apps/epauth/${name}`,
64+
method: 'GET',
65+
type,
66+
target,
67+
});
68+
69+
/** The CONTROL: an endpoint the runtime does serve, over the config's own object. */
70+
const CONTROL_ENDPOINT = {
71+
name: 'epauth_note_feed',
72+
path: '/api/v1/apps/epauth/notes',
73+
method: 'GET',
74+
type: 'object_operation',
75+
objectParams: { object: OBJECT.name, operation: 'find' },
76+
};
77+
78+
/** The refused declarations, each by the name the refusal must carry. */
79+
const REFUSED = [
80+
{ type: 'script', endpoint: endpoint('epauth_script_endpoint', 'script', 'epauth_script_handler') },
81+
{ type: 'proxy', endpoint: endpoint('epauth_proxy_endpoint', 'proxy', 'https://upstream.example.test/feed') },
82+
] as const;
83+
84+
function withConfig<T>(apis: unknown[], body: (dir: string) => T): T {
85+
const dir = mkdtempSync(join(tmpdir(), 'dogfood-endpoint-authoring-'));
86+
try {
87+
const stack = { manifest: MANIFEST, objects: [OBJECT], apis };
88+
writeFileSync(
89+
join(dir, 'objectstack.config.mjs'),
90+
`import { defineStack } from '@objectstack/spec';\n\nexport default defineStack(${JSON.stringify(stack, null, 2)}, { strict: false });\n`,
91+
);
92+
mkdirSync(join(dir, 'node_modules', '@objectstack'), { recursive: true });
93+
symlinkSync(SPEC_ROOT, join(dir, 'node_modules', '@objectstack', 'spec'), 'dir');
94+
return body(dir);
95+
} finally {
96+
rmSync(dir, { recursive: true, force: true });
97+
}
98+
}
99+
100+
function runCli(command: 'validate' | 'build', dir: string): { exitCode: number; output: string; wroteArtifact: boolean } {
101+
const res = spawnSync(process.execPath, [CLI_BIN, command], {
102+
cwd: dir,
103+
encoding: 'utf8',
104+
timeout: 120_000,
105+
env: { ...process.env, NO_COLOR: '1' },
106+
});
107+
return {
108+
exitCode: res.status ?? 1,
109+
output: `${res.stdout ?? ''}${res.stderr ?? ''}`,
110+
wroteArtifact: existsSync(join(dir, 'dist', 'objectstack.json')),
111+
};
112+
}
113+
114+
describe('[#26572] a script / proxy endpoint is refused by the authoring commands, naming it', () => {
115+
for (const command of ['validate', 'build'] as const) {
116+
it(`CONTROL — os ${command} accepts the same config with an object_operation endpoint`, () => {
117+
const run = withConfig([CONTROL_ENDPOINT], (dir) => runCli(command, dir));
118+
expect(run.exitCode, `os ${command} refused the CONTROL config:\n${run.output}`).toBe(0);
119+
}, 180_000);
120+
121+
for (const { type, endpoint: declared } of REFUSED) {
122+
it(`os ${command} refuses a \`${type}\` endpoint: non-zero, the endpoint and the type named, the flow prescription given`, () => {
123+
const run = withConfig([declared], (dir) => runCli(command, dir));
124+
expect(run.exitCode, `os ${command} exited 0 on a ${type} endpoint:\n${run.output}`).not.toBe(0);
125+
expect(run.output).toContain(declared.name);
126+
expect(run.output).toContain(`type: '${type}'`);
127+
expect(run.output).toContain("type: 'flow'");
128+
if (command === 'build') {
129+
expect(run.wroteArtifact, 'os build wrote an artifact for a config it refused').toBe(false);
130+
}
131+
}, 180_000);
132+
}
133+
}
134+
});
135+
136+
describe('[#26572] [#5488] runtime authoring of an api endpoint is withdrawn on a booted showcase', () => {
137+
let stack: VerifyStack;
138+
let admin = '';
139+
const NAME = 'showcase_runtime_authored_api';
140+
141+
beforeAll(async () => {
142+
stack = await bootShowcase({ security: showcaseAppDefaultSecurity() });
143+
admin = await stack.signIn();
144+
}, 240_000);
145+
146+
afterAll(async () => {
147+
await stack?.stop?.();
148+
});
149+
150+
it('a platform admin\'s PUT /meta/api/NAME of a well-formed flow endpoint is refused, and the store gains nothing', async () => {
151+
const res = await stack.apiAs(admin, 'PUT', `/meta/api/${NAME}`, {
152+
name: NAME,
153+
path: `/api/v1/apps/showcase/${NAME}`,
154+
method: 'GET',
155+
type: 'flow',
156+
target: 'showcase_inquiry_purge',
157+
});
158+
const body: any = await res.clone().json();
159+
// `api` is code-only in the metadata-type registry: the save door answers
160+
// its catalogued refusal, never a write.
161+
expect({ status: res.status, code: body?.code ?? body?.error?.code }, JSON.stringify(body))
162+
.toEqual({ status: 403, code: 'NOT_CREATABLE' });
163+
const read = await stack.apiAs(admin, 'GET', `/meta/api/${NAME}`);
164+
expect(read.status, await read.clone().text()).toBe(404);
165+
});
166+
167+
it('CONTROL — the code-declared endpoints are still on the metadata face', async () => {
168+
const res = await stack.apiAs(admin, 'GET', '/meta/api/showcase_task_feed');
169+
expect(res.status, await res.clone().text()).toBe(200);
170+
});
171+
});

0 commit comments

Comments
 (0)