Skip to content

Commit 0e90d2f

Browse files
test(knowledge-pgvector): live PostgreSQL case with no adapter and no requires (#38054)
repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP Fixes #38040 ## 维护者速读 - 用户无感:只是测试,不改任何运行行为。 - 补上真实 PostgreSQL 上「知识源不写存储、也不声明需要知识服务」这一条的端到端验证,承接知识检索那一组改动。 - 只是新增测试,可直接撤回;已在真实 PostgreSQL 上跑过,去掉新接线的任何一处都会让它变红。 - 需要你做的:无。 ## What changes `capability-mount.live-postgres.test.ts` gains a second block beside the explicit control: a stack that ships one `knowledge_source` with no `adapter` and lists no `knowledge` token. It asserts the item alone adds the token (`stackItemCapabilities` into `resolveServedCapabilities`, `byItems`), the deployment-store mark is `{ deploymentAdapter: 'pgvector' }` (`resolveCapabilityArgument`), the service mounts and the store is healthy, passages land in the pgvector tables of the live schema, and `search_knowledge` returns them with the source id. The explicit case is unchanged. ## Tests Live suite on private PostgreSQL 16 + pgvector (UTF8, `OS_EXPECT_LIVE_DIALECT_MATRIX=1`), head `abf7914641`, under `os-verify-lock` (`VERDICT command-exit 0`, held 186s, shared box): 1 file, 4/4 passed (2 control, 2 new). Typecheck of `knowledge-pgvector`: exit 0. Ablation 1 (`stackItemCapabilities` returns nothing, core rebuilt): the new block is red, `expected [] to deeply equal ['knowledge']`; the control passes. Ablation 2 (`resolveCapabilityArgument('knowledge')` returns no argument, core rebuilt): the new block is red, `expected undefined to deeply equal { deploymentAdapter: 'pgvector' }`; the control passes. Restored, core rebuilt (exit 0), final re-run 4/4 green. In ablation 1 the core d.ts build errored on the mutation's unused variables (TS6133), but the JS was emitted and the red shows the mutation was live. Record: comment 7230806559. ## Acceptance notes overlap-check against origin/main: VERDICT clean exit 0. No source change; no changeset (test only). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP Co-authored-by: os-dev <noreply@anthropic.com>
1 parent 7e4df28 commit 0e90d2f

1 file changed

Lines changed: 87 additions & 1 deletion

File tree

‎packages/plugins/knowledge-pgvector/src/__tests__/capability-mount.live-postgres.test.ts‎

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@
99
* and `search_knowledge` (the executor the MCP doors call) finds it. The
1010
* SQLite half of the rule boots in `@objectstack/verify`
1111
* (`harness.required-providers.test.ts`).
12+
*
13+
* The second block is the same line with neither `adapter` nor `requires`
14+
* written: the stack ships only a `knowledge_source` item, the item mounts the
15+
* service (`stackItemCapabilities`), and the source binds to the deployment's
16+
* marked store (`deploymentAdapter`, from `resolveCapabilityArgument`). The
17+
* first block stays as the explicit control.
1218
*/
1319

1420
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
15-
import { CAPABILITY_PROVIDERS, LiteKernel, resolveCapabilityExtras } from '@objectstack/core';
21+
import {
22+
CAPABILITY_PROVIDERS,
23+
LiteKernel,
24+
resolveCapabilityArgument,
25+
resolveCapabilityExtras,
26+
resolveServedCapabilities,
27+
stackItemCapabilities,
28+
} from '@objectstack/core';
1629
import { KnowledgeService, KnowledgeServicePlugin } from '@objectstack/service-knowledge';
1730
import { EMBEDDER_SERVICE } from '@objectstack/spec/contracts';
1831
import { KnowledgePgvectorPlugin } from '../index.js';
@@ -83,3 +96,76 @@ describe.skipIf(!PG_URL)('requires knowledge on PostgreSQL — the token mounts
8396
expect(JSON.stringify(answer.hits[0])).toContain('granite');
8497
});
8598
});
99+
100+
describe.skipIf(!PG_URL)('a knowledge_source with no adapter and no requires — mounted by the item, bound to the marked store', { timeout: 60_000 }, () => {
101+
let kernel: LiteKernel;
102+
let svc: KnowledgeService;
103+
const schema = store.schema();
104+
// The stack as an author writes it: one item, no `adapter`, no `requires`.
105+
const stack = {
106+
knowledgeSources: [{ name: 'kpg_bare', label: 'Bare notes', source: { kind: 'object', object: 'kpg_bare_note', content: ['body'] } }],
107+
};
108+
109+
beforeAll(async () => {
110+
// Which tokens the boot mounts: the item alone adds `knowledge`.
111+
const served = resolveServedCapabilities([], { preset: 'minimal', itemTokens: stackItemCapabilities(stack) });
112+
expect(served.tokens).toEqual(['knowledge']);
113+
expect(served.byItems.has('knowledge')).toBe(true);
114+
115+
const database = { driver: 'postgres', url: PG_URL as string };
116+
const input = { stack, packageRoot: process.cwd(), env: {}, database };
117+
// With what: the deployment's-store mark, and the store the rule mounts.
118+
const { argument: serviceArgument } = resolveCapabilityArgument('knowledge', input);
119+
expect(serviceArgument).toEqual({ deploymentAdapter: 'pgvector' });
120+
const [extra] = resolveCapabilityExtras('knowledge', input);
121+
122+
kernel = new LiteKernel({ logger: { level: 'silent' } } as never);
123+
kernel.use({
124+
name: 'test.embedder',
125+
init: async (ctx: { registerService(n: string, s: unknown): void }) => ctx.registerService(EMBEDDER_SERVICE, new FakeEmbedder()),
126+
} as never);
127+
kernel.use(
128+
new KnowledgeServicePlugin({
129+
...(serviceArgument as object),
130+
enableEventSync: false,
131+
sources: stack.knowledgeSources as never,
132+
}),
133+
);
134+
kernel.use(new KnowledgePgvectorPlugin({ ...(extra.argument as object), schema }));
135+
await kernel.bootstrap();
136+
svc = kernel.getService<KnowledgeService>('knowledge');
137+
});
138+
139+
afterAll(async () => {
140+
try { await kernel?.shutdown(); } catch { /* noop */ }
141+
await store.dropAll();
142+
});
143+
144+
it('the service is mounted, and the source is bound to the marked store', async () => {
145+
expect(svc.listAdapters()).toEqual(['pgvector']);
146+
expect(await svc.getAdapter('pgvector').healthCheck!()).toMatchObject({ ok: true });
147+
expect(svc.reportUnmountedAdapters()).toEqual([]);
148+
});
149+
150+
it('its passages land in the pgvector tables, and search_knowledge returns them', async () => {
151+
await svc.handleRecordUpsert('kpg_bare_note', { id: 'b1', body: 'basalt cliff above the harbour' });
152+
const { rows } = await store.pool().query(
153+
`SELECT table_name FROM information_schema.tables WHERE table_schema = $1`,
154+
[schema],
155+
);
156+
expect(rows.length).toBeGreaterThan(0);
157+
let stored = 0;
158+
for (const { table_name } of rows as Array<{ table_name: string }>) {
159+
const r = await store.pool().query(`SELECT count(*)::int AS n FROM "${schema}"."${table_name}"`);
160+
stored += r.rows[0].n;
161+
}
162+
expect(stored).toBeGreaterThan(0);
163+
const answer = await svc.knowledgeTools().searchKnowledge(
164+
{ query: 'basalt cliff' },
165+
{ isSystem: true, userId: 'system', roles: [], permissions: [] } as never,
166+
);
167+
expect(answer.refused).toBeUndefined();
168+
expect(answer.hits.map((h) => h.sourceId)).toEqual(['kpg_bare']);
169+
expect(JSON.stringify(answer.hits[0])).toContain('basalt');
170+
});
171+
});

0 commit comments

Comments
 (0)