Files
gstack/test/brain-cache-page-read.test.ts
T
95cf15b3c9 gbrain memory lookups find the artifacts source, product pages and newest timeline rows (#4685)
`/sync-gbrain` and `gstack-decision-search --semantic` now find a brain
host's artifacts source through `GSTACK_BRAIN_SOURCE_ID`, planning
skills read their product and brand digests from current gbrain, and the
brain gets each sync's newest artifacts and timeline rows.

Why: five outside reports (#4443, #4327, #4265, #4179, #4362), each
reproduced on main by a test that fails before this change and passes
after it.

Nothing to do unless your artifacts source lives outside
`~/.gstack-brain-worktree`; then set `GSTACK_BRAIN_SOURCE_ID` to its id.

Co-authored-by: Barack-zero-to-one <121355791+Barack-zero-to-one@users.noreply.github.com>
Co-authored-by: exGeni <135786749+exGeni@users.noreply.github.com>
Co-authored-by: atharva081106 <176514655+atharva081106@users.noreply.github.com>
Co-authored-by: extremenelson <2460114+extremenelson@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1v/outside-voice#2 reader=outside-voice
2026-11-22 11:00:45 +00:00

60 lines
2.3 KiB
TypeScript

/**
* #4265: single-page brain-cache entities read the page text gbrain's
* `get --json` actually returns (compiled_truth; body is a read-mode name),
* under the lowercased slug gbrain stores.
*/
import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { delimiter, join } from 'path';
import { tmpdir } from 'os';
const CACHE = '../bin/gstack-brain-cache';
let TMP_HOME: string;
let STUB: string;
const saved = { home: process.env.GSTACK_HOME, path: process.env.PATH };
beforeEach(() => {
TMP_HOME = mkdtempSync(join(tmpdir(), 'gstack-cache-page-'));
STUB = mkdtempSync(join(tmpdir(), 'gstack-cache-page-gbrain-'));
writeFileSync(join(STUB, 'page.json'), JSON.stringify({
slug: 'gstack/product/some-org-some-repo',
title: 'Some product',
body: 'auto',
compiled_truth: '## What it is\nA tool that ships code.',
timeline: '',
}) + '\n');
writeFileSync(join(STUB, 'gbrain'), [
'#!/bin/sh',
'here=$(dirname "$0")',
'echo "$@" >> "$here/calls"',
'[ "$1" = get ] && [ "$2" = gstack/product/some-org-some-repo ] && cat "$here/page.json" && exit 0',
'echo "page_not_found" >&2',
'exit 1',
'',
].join('\n'));
chmodSync(join(STUB, 'gbrain'), 0o755);
process.env.PATH = `${STUB}${delimiter}${saved.path ?? ''}`;
process.env.GSTACK_HOME = TMP_HOME;
delete require.cache[require.resolve(CACHE)];
});
afterEach(() => {
if (saved.home) process.env.GSTACK_HOME = saved.home; else delete process.env.GSTACK_HOME;
process.env.PATH = saved.path;
rmSync(TMP_HOME, { recursive: true, force: true });
rmSync(STUB, { recursive: true, force: true });
});
describe.skipIf(process.platform === 'win32')('brain-cache single-page read (#4265)', () => {
test('a product page under a mixed-case project slug comes back as a digest', async () => {
const mod = await import(CACHE);
const result = mod.cmdGet('product', 'Some-Org-some-repo');
expect(result.state).toBe('cold-refreshed');
const digest = readFileSync(result.path, 'utf-8');
expect(digest).toContain('# Some product');
expect(digest).toContain('A tool that ships code.');
expect(digest).not.toContain('auto');
expect(readFileSync(join(STUB, 'calls'), 'utf-8')).toContain('get gstack/product/some-org-some-repo --json');
});
});