Files
claudemesh/apps/broker/tests/encoding.test.ts
Alejandro Gutiérrez e25115f1b0 test(broker): port test suite from claude-intercom to drizzle/postgres
21 integration tests (14 broker behavior + 7 path encoding), all
passing in ~1s against a real Postgres (claudemesh_test database on
the dev container).

Test infrastructure:
- apps/broker/vitest.config.ts extends @turbostarter/vitest-config/base
- tests/helpers.ts: setupTestMesh() creates a fresh mesh + 2 members
  per test with a unique slug, returns cleanup function that cascades
  the delete. cleanupAllTestMeshes() as an afterAll safety net.
- Mesh isolation in broker logic means tests don't interfere even when
  they share a database — no per-test TRUNCATE needed.

Ported behavior tests (broker.test.ts, 14 tests):
- hook flips status + queued "next" messages unblock
- "now"-priority bypasses the working gate
- DND is sacred (hooks cannot unset it)
- hook source stays fresh through jsonl refresh
- source decays to jsonl when hook signal goes stale
- isHookFresh freshness window + source-type rules
- TTL sweep flips stuck "working" → idle
- TTL sweep leaves DND alone
- first-turn race: hook fired pre-connect stashed in pending_status
- applyPendingHookStatus picks newest matching entry
- expired pending entries are ignored on connect
- broadcast targetSpec (*) reaches all members
- pubkey mismatch → message not drained
- mesh isolation: peer in mesh X doesn't drain from mesh Y

Ported encoding tests (encoding.test.ts, 7 tests):
- macOS, Linux, Windows path encoding first-candidate correctness
- Roberto's H:\Claude → H--Claude regression test (2026-04-04)
- Candidate dedup, drive-stripped fallback, leading-dash fallback

How to run: from apps/broker,
  DATABASE_URL="postgresql://.../claudemesh_test" pnpm test

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 22:09:06 +01:00

51 lines
1.8 KiB
TypeScript

/**
* Path encoding tests — pure unit tests, no DB required.
*
* Pins Claude Code's project-key encoding across platforms:
* macOS/Linux: /Users/x/foo → -Users-x-foo
* Windows: H:\Claude → H--Claude (confirmed 2026-04-04)
* Windows: C:\Users\x → C--Users-x
*/
import { describe, expect, test } from "vitest";
import { cwdToProjectKeyCandidates } from "../src/paths";
describe("cwdToProjectKeyCandidates", () => {
test("macOS path → -Users-x-foo first", () => {
const keys = cwdToProjectKeyCandidates("/Users/agutierrez/Desktop/foo");
expect(keys[0]).toBe("-Users-agutierrez-Desktop-foo");
});
test("Linux path → -home-alice-project first", () => {
const keys = cwdToProjectKeyCandidates("/home/alice/project");
expect(keys[0]).toBe("-home-alice-project");
});
test("Windows H:\\Claude → H--Claude first (Roberto 2026-04-04)", () => {
const keys = cwdToProjectKeyCandidates("H:\\Claude");
expect(keys[0]).toBe("H--Claude");
});
test("Windows C:\\Users\\Alice\\dev\\myapp → C--Users-Alice-dev-myapp first", () => {
const keys = cwdToProjectKeyCandidates("C:\\Users\\Alice\\dev\\myapp");
expect(keys[0]).toBe("C--Users-Alice-dev-myapp");
});
test("candidates are deduped", () => {
const keys = cwdToProjectKeyCandidates("/Users/x/foo");
const unique = new Set(keys);
expect(keys.length).toBe(unique.size);
});
test("Windows path includes a drive-stripped fallback", () => {
const keys = cwdToProjectKeyCandidates("C:\\Users\\Alice");
expect(keys).toContain("-Users-Alice");
});
test("leading-dash fallback added when cwd has no leading separator", () => {
const keys = cwdToProjectKeyCandidates("project/foo");
expect(keys).toContain("project-foo");
expect(keys).toContain("-project-foo");
});
});