Skip to content

Commit 023ce05

Browse files
committed
test(#28367): test doubles honour the ledgers (limit, combinators, engine-double contract); plugin-auth reads @objectstack/rest as its other tests do
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyagSyLB5ckJsKghoa
1 parent fd116ba commit 023ce05

4 files changed

Lines changed: 23 additions & 27 deletions

File tree

‎packages/plugins/plugin-auth/vitest.config.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ export default defineConfig({
4848
find: /^@objectstack\/formula$/,
4949
replacement: path.resolve(here, '../../formula/src/index.ts'),
5050
},
51-
// [#28367] `agent-forward-identity-view.test.ts` takes a VALUE import on
52-
// `@objectstack/rest` (`withForwardCredential`): the agent forward
53-
// credential it mints is the one the identity mount redeems. Same reason
54-
// and the same anchoring as the entries above.
55-
{
56-
find: /^@objectstack\/rest$/,
57-
replacement: path.resolve(here, '../../rest/src/index.ts'),
58-
},
5951
// [#22257] `auth-settings-seeded-boot.pin.test.ts` boots the REAL
6052
// `SettingsServicePlugin` beside `AuthPlugin`: the pre-bind window it
6153
// pins is that plugin's bind hook and that service's reporter. Same

‎packages/rest/src/rest-forward-credential-agent.test.ts‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ const RAW_API_KEY = 'osk_6071_rest_face';
4545
*/
4646
const makeQl = () => bindTestSecurityCatalog({
4747
find: async (object: string, opts: any) => {
48+
const rows = rowsFor(object, opts);
49+
return typeof opts?.limit === 'number' ? rows.slice(0, opts.limit) : rows;
50+
},
51+
}, { permissions: [{ name: 'admin_full_access' }, { name: 'member_default' }] });
52+
53+
/** The rows the fake engine holds for `object`, filtered by `opts.where`. */
54+
function rowsFor(object: string, opts: any): any[] {
55+
{
4856
const where = opts?.where ?? {};
4957
if (object === 'sys_api_key') {
5058
const row = { id: 'k1', key: hashApiKey(RAW_API_KEY), revoked: false, user_id: 'member1', expires_at: FUTURE };
@@ -68,8 +76,8 @@ const makeQl = () => bindTestSecurityCatalog({
6876
].filter(Boolean);
6977
}
7078
return [];
71-
},
72-
}, { permissions: [{ name: 'admin_full_access' }, { name: 'member_default' }] });
79+
}
80+
}
7381

7482
/** A fake auth service whose session is keyed off the request's `cookie` header. */
7583
const makeAuth = () => ({
@@ -165,21 +173,6 @@ async function request(headers: Record<string, string>, auth?: unknown) {
165173
return { ctx: seen[0], out, protocol };
166174
}
167175

168-
/**
169-
* [#7280] The envelope `computeExecCtx` actually produces, read directly.
170-
*
171-
* Needed because a GATED session never reaches `findData`: `enforceAuth` answers
172-
* 403 first, which is the whole point of the gate — so the wire-capture helper
173-
* above cannot observe the envelope for exactly the case under test.
174-
*/
175-
async function execCtx(headers: Record<string, string>) {
176-
const { rest } = boot();
177-
return await (rest as any).computeExecCtx(undefined, {
178-
method: 'GET', params: { object: 'task' }, query: {}, headers,
179-
});
180-
}
181-
182-
183176
const AGENT = { userId: 'member1', clientId: 'client_agent', scopes: ['actions:execute', 'data:read', 'data:write'] };
184177
const bindForward = (method = 'GET', path = '/api/v1/data/task') =>
185178
({ method, path, run: { objectName: 'task', actionName: 'probe' }, agent: AGENT });

‎packages/runtime/src/security/resolve-execution-context.forward-credential.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ function tables(): Record<string, any[]> {
4141
};
4242
}
4343

44+
/** Equality, `$in` and a NULL column; every other shape refused loudly. */
4445
function matchesWhere(row: any, where: any): boolean {
4546
return Object.entries(where ?? {}).every(([field, cond]) => {
46-
if (cond !== null && typeof cond === 'object' && Array.isArray((cond as any).$in)) return (cond as any).$in.includes(row[field]);
47+
if (field.startsWith('$')) throw new Error(`fixture where-matcher: unsupported combinator '${field}'`);
48+
if (cond !== null && typeof cond === 'object') {
49+
if (!Array.isArray((cond as any).$in)) throw new Error(`fixture where-matcher: unsupported operator on '${field}'`);
50+
return (cond as any).$in.includes(row[field]);
51+
}
4752
if (cond === null) return (row[field] ?? null) === null;
4853
return row[field] === cond;
4954
});
@@ -55,7 +60,8 @@ function rig() {
5560
registerMiddleware: () => undefined,
5661
getSchema: () => undefined,
5762
async find(object: string, q: any = {}) {
58-
return (t[object] ?? []).filter((r) => matchesWhere(r, q?.where));
63+
const rows = (t[object] ?? []).filter((r) => matchesWhere(r, q?.where));
64+
return typeof q?.limit === 'number' ? rows.slice(0, q.limit) : rows;
5965
},
6066
async findOne(object: string, q: any = {}) {
6167
assertEngineFindOnePredicate(object, q);

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4676,6 +4676,11 @@
46764676
"verb": "findOne",
46774677
"pinned": 1
46784678
},
4679+
{
4680+
"file": "packages/runtime/src/security/resolve-execution-context.forward-credential.test.ts",
4681+
"verb": "findOne",
4682+
"pinned": 1
4683+
},
46794684
{
46804685
"file": "packages/runtime/src/security/resolve-execution-context.oauth-organization.test.ts",
46814686
"verb": "findOne",

0 commit comments

Comments
 (0)