Skip to content

Commit 221e401

Browse files
committed
test(runtime): the unmounted-adapter duplicate case reads the service's duplicate-door sentence
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
1 parent d547136 commit 221e401

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎packages/runtime/src/domains/packages-knowledge-source-gate.test.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ describe('/packages — duplicate admits each knowledge source it copies for the
239239
message: "The knowledge source \"faq\" was not saved: you may not query field 'salary' of object 'article'.",
240240
};
241241
/** A stack whose kernel also serves a knowledge service answering `admit`. */
242-
function withKnowledge(holding: Holding, admit: (item: unknown, ctx: unknown) => unknown) {
243-
const admitAuthoredSource = vi.fn(async (item: unknown, c: unknown) => admit(item, c));
242+
function withKnowledge(holding: Holding, admit: (item: unknown, ctx: unknown, options?: { door?: unknown }) => unknown) {
243+
const admitAuthoredSource = vi.fn(async (item: unknown, c: unknown, options?: { door?: unknown }) => admit(item, c, options));
244244
return { ...make(holding, { admitAuthoredSource }), admitAuthoredSource };
245245
}
246246

@@ -256,24 +256,31 @@ describe('/packages — duplicate admits each knowledge source it copies for the
256256
expect(s.admitAuthoredSource).toHaveBeenCalledWith(SOURCE_ITEM, caller.executionContext, { door: 'duplicate' });
257257
});
258258

259-
// The save refusal of a source whose `adapter` the deployment does not
260-
// mount is a `400`, where the gates' own are `403`: the door answers the
261-
// predicate's status and sentence, never one of its own.
262-
it('a source naming an adapter the deployment does not mount refuses the duplicate 400 VALIDATION_ERROR with the save\'s sentence, and nothing is copied', async () => {
263-
const UNMOUNTED = {
259+
// The refusal of a source whose `adapter` the deployment does not mount is
260+
// a `400`, where the gates' own are `403`: the door answers the service's
261+
// status and its sentence for this door, worded for the duplicate's caller
262+
// (the service is asked with `door: 'duplicate'`), never one of its own.
263+
it('a source naming an adapter the deployment does not mount refuses the duplicate 400 VALIDATION_ERROR with the service\'s duplicate-door sentence, and nothing is copied', async () => {
264+
const verdictFor = (door: unknown) => ({
264265
admitted: false, status: 400, code: 'VALIDATION_ERROR',
265-
message: "The knowledge source \"faq\" was not saved: it names adapter 'ragflow', which this deployment does not mount (mounted: memory).",
266-
};
266+
message: door === 'duplicate'
267+
? "The knowledge source \"faq\" cannot be copied: it names adapter 'ragflow', which this deployment does not mount (mounted: memory), and a source's `adapter` must name a mounted store. Mount the 'ragflow' store and duplicate the package again."
268+
: "The knowledge source \"faq\" was not saved: it names adapter 'ragflow', which this deployment does not mount (mounted: memory), and a source's `adapter` must name a mounted store. Mount the 'ragflow' store and save it again.",
269+
});
267270
const held = { ...SOURCE_ITEM, adapter: 'ragflow' };
268-
const s = withKnowledge({ items: [held] }, () => UNMOUNTED);
271+
const s = withKnowledge({ items: [held] }, (_item: unknown, _ctx: unknown, options?: { door?: unknown }) => verdictFor(options?.door));
269272
const caller = authed(BOTH);
270273
const r = await call(s, DUPLICATE, caller);
271274
expect(r.response?.status).toBe(400);
272275
expect(r.response?.body?.error?.code).toBe('VALIDATION_ERROR');
273-
expect(r.response?.body?.error?.message).toContain('nothing was copied');
274-
expect(r.response?.body?.error?.message).toContain(UNMOUNTED.message);
276+
const message: string = r.response?.body?.error?.message;
277+
expect(message).toContain(verdictFor('duplicate').message);
278+
expect(message).toContain('cannot be copied');
279+
expect(message).toMatch(/duplicate the package again/i);
280+
expect(message).not.toMatch(/save the source|save it again|Nothing was written|was not saved/);
281+
expect(message.match(/nothing was copied/gi)).toHaveLength(1);
275282
expect(s.protocol.duplicatePackage).not.toHaveBeenCalled();
276-
expect(s.admitAuthoredSource).toHaveBeenCalledWith(held, caller.executionContext);
283+
expect(s.admitAuthoredSource).toHaveBeenCalledWith(held, caller.executionContext, { door: 'duplicate' });
277284
});
278285

279286
it('every source is asked about: the second one refused refuses the duplicate', async () => {

0 commit comments

Comments
 (0)