Files
kbdb-graph-plugin/tests/graph-source.test.ts
T
Claude 4190fbcf90 feat(graph): owner_id 寫入鏈必經(根治無主資料)——配合 base owner-mandatory(D28)
- kbdb-client requireOwner 守衛:漏 owner 插件端即 throw,不再靜默送 owner:''
- owner 一路 thread:persistNodes/ingestEnvelope/entity-crud/triplet-crud 全必填
- 病灶修:POST /triplets/ingest 原本沒傳 owner→加 owner_id query+400
- 寫入 route 缺 owner→400;vitest 23→27
- 註:gloss-bridge 分支的 backfill/gloss-entry 另需套 owner 必填(附說明),不跨支疊改
2026-07-05 11:00:30 +00:00

50 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// get_source + refreshC 段)— 走 mock,零 SQL、不打真網路。
import { describe, it, expect } from 'vitest';
import { ingestEnvelope } from '../src/actions/triplet-ingest';
import { getSource } from '../src/actions/graph-source';
import { refreshSource } from '../src/actions/graph-refresh';
import { mockClient } from './mock-client';
describe('getSource — 回節點的原文來源指標', () => {
it('回觸及節點的 triplet 的 uri + anchor', async () => {
const c = mockClient();
await ingestEnvelope(c, {
source: { uri: 'github:u/w@a.md', content_hash: 'h1', anchor: '#graph-rag' },
extractor: { model: 'm', tier: 'deep' },
triplets: [{ subject: 'GraphRAG', predicate: '是', object: 'RAG 變體' }],
}, 'leo');
const refs = await getSource(c, 'GraphRAG');
expect(refs.length).toBe(1);
expect(refs[0].uri).toBe('github:u/w@a.md');
expect(refs[0].anchor).toBe('#graph-rag');
expect(refs[0].edge).toEqual({ subject: 'GraphRAG', predicate: '是', object: 'RAG 變體' });
});
it('deprecated triplet 不出現在 get_sourceactive-only', async () => {
const c = mockClient();
await ingestEnvelope(c, {
source: { uri: 'github:u/w@a.md', content_hash: 'h1', anchor: '#old' },
extractor: { model: 'm', tier: 'deep' },
triplets: [{ subject: 'X', predicate: 'r', object: 'old' }],
}, 'leo');
await ingestEnvelope(c, {
source: { uri: 'github:u/w@a.md', content_hash: 'h2', anchor: '#new' },
extractor: { model: 'm', tier: 'deep' },
triplets: [{ subject: 'X', predicate: 'r', object: 'new' }],
}, 'leo');
const refs = await getSource(c, 'X');
expect(refs.length).toBe(1);
expect(refs[0].anchor).toBe('#new'); // 只見 active 批
});
});
describe('refreshSource — 代轉 ingest(人發起)', () => {
it('KBDB_INGEST_URL 未設 → 誠實回 forwarded:false,不假裝成功', async () => {
const res = await refreshSource({ uri: 'github:u/w@a.md' }, undefined);
expect(res.forwarded).toBe(false);
expect(res.note).toMatch(/未就緒|未設/);
});
});