mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-20 08:40:11 +02:00
fix(learnings): preserve current entries in cross-project search
This commit is contained in:
@@ -12,6 +12,7 @@ const tmpCwd = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-search-cwd-'));
|
||||
// gstack-slug derives slug from git remote (none here) → falls back to basename of cwd.
|
||||
const slug = path.basename(tmpCwd).replace(/[^a-zA-Z0-9._-]/g, '');
|
||||
const projDir = path.join(tmpHome, 'projects', slug);
|
||||
const otherProjDir = path.join(tmpHome, 'projects', 'other-project');
|
||||
|
||||
function run(args: string[]): string {
|
||||
return execFileSync(BIN, args, {
|
||||
@@ -23,12 +24,18 @@ function run(args: string[]): string {
|
||||
|
||||
beforeAll(() => {
|
||||
fs.mkdirSync(projDir, { recursive: true });
|
||||
fs.mkdirSync(otherProjDir, { recursive: true });
|
||||
const entries = [
|
||||
{ ts: '2026-05-01T00:00:00Z', skill: 'test', type: 'pattern', key: 'foo-pattern', insight: 'A foo-related insight', confidence: 8, source: 'observed', files: [] },
|
||||
{ ts: '2026-05-02T00:00:00Z', skill: 'test', type: 'pitfall', key: 'bar-pitfall', insight: 'A bar-related insight', confidence: 8, source: 'observed', files: [] },
|
||||
{ ts: '2026-05-03T00:00:00Z', skill: 'test', type: 'pattern', key: 'baz-pattern', insight: 'A baz-related insight', confidence: 8, source: 'observed', files: [] },
|
||||
{ ts: '2026-05-01T00:00:00Z', skill: 'test', type: 'pattern', key: 'foo-pattern', insight: 'A foo-related insight', confidence: 8, source: 'observed', trusted: false, files: [] },
|
||||
{ ts: '2026-05-02T00:00:00Z', skill: 'test', type: 'pitfall', key: 'bar-pitfall', insight: 'A bar-related insight', confidence: 8, source: 'observed', trusted: false, files: [] },
|
||||
{ ts: '2026-05-03T00:00:00Z', skill: 'test', type: 'pattern', key: 'baz-pattern', insight: 'A baz-related insight', confidence: 8, source: 'observed', trusted: false, files: [] },
|
||||
];
|
||||
const otherEntries = [
|
||||
{ ts: '2026-05-04T00:00:00Z', skill: 'test', type: 'pattern', key: 'foreign-observed', insight: 'A foreign observed insight', confidence: 8, source: 'observed', trusted: false, files: [] },
|
||||
{ ts: '2026-05-05T00:00:00Z', skill: 'test', type: 'pattern', key: 'foreign-user', insight: 'A foreign user-stated insight', confidence: 8, source: 'user-stated', trusted: true, files: [] },
|
||||
];
|
||||
fs.writeFileSync(path.join(projDir, 'learnings.jsonl'), entries.map(e => JSON.stringify(e)).join('\n') + '\n');
|
||||
fs.writeFileSync(path.join(otherProjDir, 'learnings.jsonl'), otherEntries.map(e => JSON.stringify(e)).join('\n') + '\n');
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
@@ -58,3 +65,18 @@ describe('gstack-learnings-search token-OR query semantics', () => {
|
||||
expect(out).toContain('baz-pattern');
|
||||
});
|
||||
});
|
||||
|
||||
describe('gstack-learnings-search cross-project trust gating', () => {
|
||||
test('cross-project mode still includes observed entries from the current project', () => {
|
||||
const out = run(['--cross-project', '--query', 'foo']);
|
||||
expect(out).toContain('foo-pattern');
|
||||
expect(out).not.toContain('[cross-project]');
|
||||
});
|
||||
|
||||
test('cross-project mode only imports trusted entries from other projects', () => {
|
||||
const out = run(['--cross-project', '--query', 'foreign']);
|
||||
expect(out).toContain('foreign-user');
|
||||
expect(out).toContain('[cross-project]');
|
||||
expect(out).not.toContain('foreign-observed');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user