feat(graph): get_source + refresh 端點 + keyword 收斂 (T3.6-3.7)
對應 issue #1 T3 C 段(圖工具 HTTP API 備好,MCP 註冊薄殼待 arcrun)。 - get_source (3.7): graph-source.ts + GET /graph/source/:name — 回節點的 active triplet 來源指標(uri/anchor/block_id/content_hash),去重。 連帶加 source_anchor slot,ingest 從 source.anchor 帶入 - refresh (3.6/3.6b): graph-refresh.ts + POST /graph/refresh — 純被動代轉 ingest(KBDB_INGEST_URL),只人發起、無排程/webhook(fan-out 紅線)。 未設 URL → 誠實 forwarded:false,不假綠 - 3.6d: POST /search 移除公開 keyword 模式(重複 KBDB MCP),收斂 suggest-only; keywordSearch helper 留作 suggest 內部建構塊 - 3 新測試(get_source uri+anchor / active-only / refresh 未就緒誠實回報) gates: vitest 19 passed / zero SQL / 無新綁定 / dry-run bundle 乾淨 待接:MCP 註冊薄殼併 arcrun u6u-mcp-server;refresh 端到端待 ingest(T4) 部署 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
// get_source + refresh(C 段)— 走 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 變體' }],
|
||||
});
|
||||
|
||||
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_source(active-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' }],
|
||||
});
|
||||
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' }],
|
||||
});
|
||||
|
||||
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(/未就緒|未設/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user