mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-30 03:12:32 +00:00
* test(e2e): drop flaky wall-clock bounds in minions-resilience
The runaway-dead-letter and cascade-kill tests asserted tight real-clock
upper bounds (<2000ms, <3000ms) on top of already-complete terminal-state
checks. Those bounds carry no correctness signal — the dead/cancelled status
and abortedChildren==10 assertions fully prove behavior — and flake on loaded
CI runners where the stall/timeout sweep cadence varies. Removed both bounds,
kept the diagnostic values, de-promised the test titles.
* test(e2e): kill order-dependence + no-op assertions in mechanical
- traverse_graph: self-contained (re-adds its own idempotent link) and asserts
the linked company is reachable, instead of depending on a prior it() and
only checking array shape.
- file_list-without-slug: seeds its own >100 rows instead of relying on the
previous test's 150 surviving in the DB; asserts the cap is exercised.
- precision@5: add a loose floor (every known-item query surfaces >=1 truth doc
in top-5) so a 0% retrieval regression no longer passes silently.
- get_health: assert value bounds (page_count==16, embed_coverage 0..1) not just
typeof; get_chunks: assert non-empty text, numeric non-decreasing chunk_index,
and that the page name appears, instead of toBeTruthy on chunks[0].
* test(e2e): strengthen graph/search quality assertions + close coverage gaps
graph-quality: truncate+reseed 'config' in truncateAll (kills config leak where a
setConfig test throwing before its finally bleeds into later tests); replace
toBeGreaterThan(0) link/timeline floors with fixture-derived minimums; assert exact
attendee slugs are 'attended' instead of a vacuous .every; pin autoLinks.created to
the provable 2 (Alice+Acme); add direction out/both + depth:2 multi-hop and a
cycle-safety (A->B->A terminates) test.
search-quality: fix the vacuous detail=low vector test; assert pedro returns >=2
chunks; assert detail=high includes the timeline chunk; add empty-query and
zero-vector no-throw edge tests.
* test(e2e): self-contain multi-source sync test + assert ledger cascade
Break the sequential dependency where 'performSync no sourceId' relied on a prior
test writing sync.repo_path — it now sets its own config. Add the missing
file_migration_ledger COUNT(*)==0 cascade assertion. Tighten the source_id default
check from toContain('default') to exact "'default'::text".
* test(e2e): make migration-flow HOME/PATH swap throw-safe
The suite repoints process.env.HOME/PATH to a temp dir and only restored them in
afterAll, so a mid-test throw left HOME dead for the rest of the bun process and
silently broke sibling suites. Wrap each test body in try/finally restore + a
defensive restore at the top of beforeEach.
* test(e2e): loud-skip jsonb-roundtrip + doctor-progress
Both skipped silently with no DATABASE_URL, giving zero signal the regression guard
never ran. Add the console.log skip line matching the sibling e2e files.
* test(e2e): robust check-update contract + find_orphans tool coverage
upgrade: the 'no-releases' test hard-asserted update_available===false, which flips
to failing the moment the repo has a real release. Assert the JSON contract shape
(boolean update_available, current_version===VERSION, typed optional fields) instead.
mcp: add find_orphans to the asserted generated tool names.
134 lines
5.1 KiB
TypeScript
134 lines
5.1 KiB
TypeScript
/**
|
|
* E2E JSONB Roundtrip Tests — v0.12.1 Reliability Wave
|
|
*
|
|
* Guards the four JSONB write sites against double-encoding regressions:
|
|
* 1. PostgresEngine.putPage → pages.frontmatter
|
|
* 2. PostgresEngine.putRawData → raw_data.data
|
|
* 3. PostgresEngine.logIngest → ingest_log.pages_updated
|
|
* 4. commands/files.ts:254 → files.metadata
|
|
*
|
|
* The v0.12.0 bug: `${JSON.stringify(x)}::jsonb` sends a JSON-encoded string
|
|
* to postgres.js, which stores it as a JSONB *string literal* instead of an
|
|
* object. `col ->> 'key'` returns NULL; GIN indexes are ineffective.
|
|
* PGLite masks this because its driver parses the string. Real Postgres does not.
|
|
*
|
|
* The fix: `sql.json(x)` uses postgres.js v3's native JSONB serialization.
|
|
*/
|
|
|
|
import { describe, test, expect, beforeAll, afterAll } from 'bun:test';
|
|
import { hasDatabase, setupDB, teardownDB, getEngine, getConn } from './helpers.ts';
|
|
|
|
const skip = !hasDatabase();
|
|
const describeE2E = skip ? describe.skip : describe;
|
|
|
|
if (skip) {
|
|
console.log('Skipping E2E JSONB roundtrip tests (DATABASE_URL not set)');
|
|
}
|
|
|
|
describeE2E('E2E: JSONB roundtrip — v0.12.1 reliability wave', () => {
|
|
beforeAll(async () => { await setupDB(); });
|
|
afterAll(async () => { await teardownDB(); });
|
|
|
|
test('putPage writes frontmatter as object, not double-encoded string', async () => {
|
|
const engine = getEngine();
|
|
await engine.putPage('test/jsonb-putpage', {
|
|
type: 'concept',
|
|
title: 'JSONB putPage test',
|
|
compiled_truth: 'body',
|
|
timeline: '',
|
|
frontmatter: { marker: 'putpage-value', tags: ['a', 'b'] },
|
|
});
|
|
const sql = getConn();
|
|
const [row] = await sql`
|
|
SELECT jsonb_typeof(frontmatter) AS t, frontmatter ->> 'marker' AS marker
|
|
FROM pages WHERE slug = 'test/jsonb-putpage'
|
|
`;
|
|
expect(row.t).toBe('object');
|
|
expect(row.marker).toBe('putpage-value');
|
|
}, 30_000);
|
|
|
|
test('putRawData writes raw_data.data as object, not double-encoded string', async () => {
|
|
const engine = getEngine();
|
|
await engine.putPage('test/jsonb-rawdata', {
|
|
type: 'concept',
|
|
title: 'RawData test',
|
|
compiled_truth: 'body',
|
|
timeline: '',
|
|
frontmatter: {},
|
|
});
|
|
await engine.putRawData('test/jsonb-rawdata', 'unit-test', {
|
|
marker: 'rawdata-value',
|
|
nested: { k: 'v' },
|
|
});
|
|
const sql = getConn();
|
|
const [row] = await sql`
|
|
SELECT jsonb_typeof(rd.data) AS t, rd.data ->> 'marker' AS marker
|
|
FROM raw_data rd
|
|
JOIN pages p ON p.id = rd.page_id
|
|
WHERE p.slug = 'test/jsonb-rawdata'
|
|
`;
|
|
expect(row.t).toBe('object');
|
|
expect(row.marker).toBe('rawdata-value');
|
|
});
|
|
|
|
test('logIngest writes pages_updated as array, not double-encoded string', async () => {
|
|
const engine = getEngine();
|
|
await engine.logIngest({
|
|
source_type: 'unit-test',
|
|
source_ref: 'jsonb-roundtrip',
|
|
pages_updated: ['test/a', 'test/b', 'test/c'],
|
|
summary: 'jsonb logingest check',
|
|
});
|
|
const sql = getConn();
|
|
const [row] = await sql`
|
|
SELECT jsonb_typeof(pages_updated) AS t,
|
|
jsonb_array_length(pages_updated) AS n,
|
|
pages_updated ->> 0 AS first
|
|
FROM ingest_log
|
|
WHERE source_ref = 'jsonb-roundtrip'
|
|
ORDER BY id DESC LIMIT 1
|
|
`;
|
|
expect(row.t).toBe('array');
|
|
expect(Number(row.n)).toBe(3);
|
|
expect(row.first).toBe('test/a');
|
|
});
|
|
|
|
// files.ts:254 (uploadRaw's cloud-upload branch) was changed from
|
|
// `${JSON.stringify({...})}::jsonb` to `${sql.json({...})}` in v0.12.1.
|
|
// The function reads config and touches cloud storage, so we exercise the
|
|
// driver-level pattern directly against the same table/column.
|
|
test('files.metadata writes as object via sql.json(), not double-encoded string', async () => {
|
|
const sql = getConn();
|
|
const payload = { type: 'pdf', upload_method: 'TUS resumable' };
|
|
await sql`
|
|
INSERT INTO files (page_slug, filename, storage_path, mime_type, size_bytes, content_hash, metadata)
|
|
VALUES (NULL, 'jsonb-check.bin', 'unsorted/jsonb-check.bin', 'application/octet-stream', 1, 'sha256:deadbeef', ${sql.json(payload)})
|
|
ON CONFLICT (storage_path) DO UPDATE SET metadata = EXCLUDED.metadata
|
|
`;
|
|
const [row] = await sql`
|
|
SELECT jsonb_typeof(metadata) AS t,
|
|
metadata ->> 'type' AS type,
|
|
metadata ->> 'upload_method' AS method
|
|
FROM files WHERE storage_path = 'unsorted/jsonb-check.bin'
|
|
`;
|
|
expect(row.t).toBe('object');
|
|
expect(row.type).toBe('pdf');
|
|
expect(row.method).toBe('TUS resumable');
|
|
});
|
|
|
|
// Source-level tripwire: if anyone re-introduces the old `${JSON.stringify(x)}::jsonb`
|
|
// pattern for the fixed sites, fail loudly. Greps actual source files per the
|
|
// files-test-reimplements-production tripwire (CLAUDE.md).
|
|
test('no ${JSON.stringify(x)}::jsonb pattern remains in fixed sites', async () => {
|
|
const files = [
|
|
'../../src/core/postgres-engine.ts',
|
|
'../../src/commands/files.ts',
|
|
];
|
|
const bad = /\$\{[^}]*JSON\.stringify\([^}]*\)[^}]*\}::jsonb/;
|
|
for (const rel of files) {
|
|
const source = await Bun.file(new URL(rel, import.meta.url)).text();
|
|
expect(source.match(bad)?.[0] ?? null).toBeNull();
|
|
}
|
|
});
|
|
});
|