Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odysseus-finance-example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-module-finance": patch
---

Use an Odysseus-world legal-name example in the starter ledger comment.
2 changes: 1 addition & 1 deletion packages/module-finance/templates/ledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
type: finance
client: __SLUG__ # stable slug; must match the directory name
display_name: __DISPLAY__ # human-readable name shown in reports
# legal_name: Acme Corporation LLC # optional; full legal entity name
# legal_name: Ithaca Fleet # optional; full legal entity name
currency: __CURRENCY__ # ISO code; drives money formatting (USD/EUR special-cased)
status: active # free-form label: active | inactive | archived
terms_days: __TERMS__ # payment terms in days; overdue = issued + terms_days
Expand Down
38 changes: 19 additions & 19 deletions packages/module-finance/tests/finance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ function reportFor(slug: string) {
describe("ledger computation", () => {
test("loads all fixture ledgers", () => {
const ledgers = loadLedgers(OPTS);
expect(ledgers.map((l) => l.slug).sort()).toEqual(["acme-corp", "globex", "initech"]);
expect(ledgers.map((l) => l.slug).sort()).toEqual(["ithaca-fleet", "ithaca-shipwrights", "phaeacian-fleet"]);
});

test("partial payment leaves the invoice partial with the right open balance", () => {
const c = reportFor("acme-corp");
const inv01 = c.invoices.find((i) => i.number === "2026-acme-corp-01")!;
const inv02 = c.invoices.find((i) => i.number === "2026-acme-corp-02")!;
const c = reportFor("ithaca-fleet");
const inv01 = c.invoices.find((i) => i.number === "2026-ithaca-fleet-01")!;
const inv02 = c.invoices.find((i) => i.number === "2026-ithaca-fleet-02")!;
expect(inv01.status).toBe("paid");
expect(inv01.open).toBe(0);
expect(inv02.status).toBe("partial");
Expand All @@ -55,7 +55,7 @@ describe("ledger computation", () => {
});

test("a shortfall within fee tolerance settles the invoice as paid", () => {
const c = reportFor("globex");
const c = reportFor("phaeacian-fleet");
const inv = c.invoices[0];
expect(inv.paid).toBe(975);
expect(inv.open).toBe(0);
Expand All @@ -64,14 +64,14 @@ describe("ledger computation", () => {
});

test("a shortfall above fee tolerance stays open", () => {
const ledger = loadLedgers(OPTS, "globex")[0];
const ledger = loadLedgers(OPTS, "phaeacian-fleet")[0];
const strict = computeClient(ledger, 10, AS_OF); // tolerance below the 25 shortfall
expect(strict.invoices[0].open).toBe(25);
expect(strict.invoices[0].status).toBe("partial");
});

test("a written_off invoice carries the written_off status", () => {
const c = reportFor("initech");
const c = reportFor("ithaca-shipwrights");
expect(c.invoices[0].status).toBe("written_off");
});
});
Expand Down Expand Up @@ -129,20 +129,20 @@ describe("the generated region (#403)", () => {
test("a ledger carrying the old markers is rewritten to core's region, with today's tables", () => {
const root = copyFixtures();
try {
const path = join(root, "clients/acme-corp/ledger.md");
const path = join(root, "clients/ithaca-fleet/ledger.md");
const prose = "Hand-written notes that must survive.";
writeFileSync(path, `${readFileSync(path, "utf8").trimEnd()}\n\n${prose}\n\n${LEGACY_BEGIN}\n\nold table\n\n${LEGACY_END}\n\nClosing words.\n`);
const opts = { ...OPTS, root };

const { files } = syncFiles(opts, AS_OF);
expect(files).toContain("clients/acme-corp/ledger.md");
expect(files).toContain("clients/ithaca-fleet/ledger.md");
const body = readFileSync(path, "utf8");
expect(body).not.toContain("BEGIN GENERATED");
expect(body).not.toContain("old table");
expect(body).toContain(`${prose}\n\n<!-- brain:generated:finance -->`);
expect(body).toContain("<!-- /brain:generated:finance -->\n\nClosing words.\n");

const ledger = loadLedgers(opts, "acme-corp")[0];
const ledger = loadLedgers(opts, "ithaca-fleet")[0];
const expected = renderLedgerTables(computeClient(ledger, opts.feeTolerance, AS_OF), ledger.payments);
expect(expected.length).toBeGreaterThan(0);
expect(readGeneratedRegion(body, "finance")).toBe(expected);
Expand All @@ -161,22 +161,22 @@ describe("the generated region (#403)", () => {
test("frontmatter text that looks like a marker, a pipe or a line break stays inside its cell, on the ledger and the dashboard", () => {
const root = copyFixtures();
try {
const ledger = join(root, "clients/acme-corp/ledger.md");
const ledger = join(root, "clients/ithaca-fleet/ledger.md");
const CLOSE = "<!-- /brain:generated:finance -->";
writeFileSync(
ledger,
readFileSync(ledger, "utf8")
.replace("display_name: Acme Corporation", `display_name: "Acme | Corp\\n${CLOSE}"`)
.replace("client: acme-corp", `client: "acme-corp\\n${CLOSE}\\n(x)"`)
.replace("number: 2026-acme-corp-01", 'number: "2026-acme|01"')
.replace("invoice: 2026-acme-corp-01", 'invoice: "2026-acme|01"')
.replace("display_name: Ithaca Fleet", `display_name: "Ithaca | Fleet\\n${CLOSE}"`)
.replace("client: ithaca-fleet", `client: "ithaca-fleet\\n${CLOSE}\\n(x)"`)
.replace("number: 2026-ithaca-fleet-01", 'number: "2026-ithaca|01"')
.replace("invoice: 2026-ithaca-fleet-01", 'invoice: "2026-ithaca|01"')
.replace("method: wire", `method: "wire\\n${CLOSE}\\nrest"`)
);
const dashboard = join(root, "clients/_index.md");
writeFileSync(dashboard, "---\ntype: index\ntitle: Clients\nupdated: 2026-01-01\n---\n\n# Clients\n");
const opts = { ...OPTS, root };

expect(syncFiles(opts, AS_OF).files.sort()).toContain("clients/acme-corp/ledger.md");
expect(syncFiles(opts, AS_OF).files.sort()).toContain("clients/ithaca-fleet/ledger.md");
for (const path of [ledger, dashboard]) {
const text = readFileSync(path, "utf8");
const markerLines = text.split("\n").filter((line) => line.trim().startsWith("<!--") && line.includes("brain:generated:finance"));
Expand All @@ -188,10 +188,10 @@ describe("the generated region (#403)", () => {
expect({ path, unclosedRows: rows.filter((row) => !row.endsWith("|")) }).toEqual({ path, unclosedRows: [] });
}
expect(readGeneratedRegion(readFileSync(ledger, "utf8"), "finance")).toContain("wire &lt;!-- /brain:generated:finance --> rest");
expect(readGeneratedRegion(readFileSync(ledger, "utf8"), "finance")).toContain("| 2026-acme\\|01 |");
expect(readGeneratedRegion(readFileSync(dashboard, "utf8"), "finance")).toContain("Acme \\| Corp &lt;!--");
expect(readGeneratedRegion(readFileSync(ledger, "utf8"), "finance")).toContain("| 2026-ithaca\\|01 |");
expect(readGeneratedRegion(readFileSync(dashboard, "utf8"), "finance")).toContain("Ithaca \\| Fleet &lt;!--");
// The client directory is a link destination: percent-encoded, not escaped.
expect(readGeneratedRegion(readFileSync(dashboard, "utf8"), "finance")).toContain("](acme-corp%0A%3C!--%20%2Fbrain%3Agenerated%3Afinance%20--%3E%0A(x)/)");
expect(readGeneratedRegion(readFileSync(dashboard, "utf8"), "finance")).toContain("](ithaca-fleet%0A%3C!--%20%2Fbrain%3Agenerated%3Afinance%20--%3E%0A(x)/)");
// A second sync reads its own output back and writes nothing.
expect(syncFiles(opts, AS_OF).files).toEqual([]);
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
type: finance
client: acme-corp
display_name: Acme Corporation
client: ithaca-fleet
display_name: Ithaca Fleet
currency: USD
status: active
terms_days: 30
created: 2026-01-01
updated: 2026-01-01
invoices:
- number: 2026-acme-corp-01
- number: 2026-ithaca-fleet-01
period: 2026-01
issued: 2026-01-15
hours: 40
amount: 4000
note: Fully paid.
- number: 2026-acme-corp-02
- number: 2026-ithaca-fleet-02
period: 2026-01
issued: 2026-01-15
hours: 20
Expand All @@ -26,17 +26,17 @@ payments:
fee: 0
method: wire
allocations:
- invoice: 2026-acme-corp-01
- invoice: 2026-ithaca-fleet-01
amount: 4000
- date: 2026-01-25
received: 1000
fee: 0
method: wire
allocations:
- invoice: 2026-acme-corp-02
- invoice: 2026-ithaca-fleet-02
amount: 1000
---

# Acme Corporation
# Ithaca Fleet

Fixture ledger: one fully paid invoice and one partially paid invoice.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
type: finance
client: initech
display_name: Initech
client: ithaca-shipwrights
display_name: Ithaca Shipwrights
currency: EUR
status: active
terms_days: 30
created: 2026-01-01
updated: 2026-01-01
invoices:
- number: 2026-initech-01
- number: 2026-ithaca-shipwrights-01
period: 2026-01
issued: 2026-01-05
amount: 5000
Expand All @@ -17,6 +17,6 @@ invoices:
payments: []
---

# Initech
# Ithaca Shipwrights

Fixture ledger: a single written-off invoice.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
type: finance
client: globex
display_name: Globex
client: phaeacian-fleet
display_name: Phaeacian Fleet
currency: USD
status: active
terms_days: 30
created: 2026-01-01
updated: 2026-01-01
invoices:
- number: 2026-globex-01
- number: 2026-phaeacian-fleet-01
period: 2026-01
issued: 2026-01-10
amount: 1000
Expand All @@ -19,10 +19,10 @@ payments:
fee: 0
method: wire
allocations:
- invoice: 2026-globex-01
- invoice: 2026-phaeacian-fleet-01
amount: 975
---

# Globex
# Phaeacian Fleet

Fixture ledger: a 25.00 shortfall that the fee-tolerance rule zeroes out.
6 changes: 3 additions & 3 deletions packages/ui-react/tests/file-link-detection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ describe("entity-tag + bare-path interaction", () => {
});

test("entity content without a path stays as plain text", () => {
const md = renderEntityTags("Met <co>Acme</co> today.");
const md = renderEntityTags("Met <co>Ithaca Fleet</co> today.");
const tokens = tokenize(md, true, true);
const entity = tokens.find((t) => t.type === "entity");
if (entity?.type !== "entity") throw new Error("not entity");
expect(entity.tag).toBe("co");
expect(entity.inner).toEqual([{ type: "text", value: "Acme" }]);
expect(entity.inner).toEqual([{ type: "text", value: "Ithaca Fleet" }]);
});

test("entity content with mixed text and path", () => {
Expand All @@ -198,7 +198,7 @@ describe("entity-tag + bare-path interaction", () => {
});

test("top-level text outside entity tags is still linkified", () => {
const md = renderEntityTags("From notes/a.md to <co>Acme</co>.");
const md = renderEntityTags("From notes/a.md to <co>Ithaca Fleet</co>.");
const tokens = tokenize(md, true, true);
expect(tokens[0]).toEqual({ type: "text", value: "From " });
expect(tokens[1]).toEqual({ type: "path", value: "notes/a.md" });
Expand Down
6 changes: 3 additions & 3 deletions packages/ui-server/tests/backend-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@ describe("static registry (test/embedder seam)", () => {
test("keeps a by-value descriptor resolution's hooks and model source", async () => {
const backend = makeFakeBackend({
id: "custom",
profiles: [{ id: "custom-pro", label: "Custom Pro", vendor: "acme" }],
profiles: [{ id: "custom-pro", label: "Custom Pro", vendor: "ithaca" }],
});
const modelSource: BackendModelSource = {
list: () => [{ id: "custom-pro", label: "Custom Pro", vendor: "acme" }],
list: () => [{ id: "custom-pro", label: "Custom Pro", vendor: "ithaca" }],
state: () => ({ enabled: true, refreshedAt: 1, stale: false }),
ensureFresh: async () => {},
refresh: async () => {},
Expand All @@ -598,7 +598,7 @@ describe("static registry (test/embedder seam)", () => {
parse() {
return {
ok: true,
profiles: [{ id: "custom-pro", label: "Custom Pro", vendor: "acme" }],
profiles: [{ id: "custom-pro", label: "Custom Pro", vendor: "ithaca" }],
};
},
},
Expand Down
Loading