feat(linkedin-studio): RE-R2a — item→store capture bridge + publishedAt persistence (schema v1→v2, lossless migrate) [skip-docs]
Closes the research-engine capture loop RE-R1 deferred:
- itemToInput(item, capturedAt): pure envelope→TrendInput bridge in item.ts —
injects capturedAt, carries publishedAt verbatim; no id, no re-validate
- publishedAt persisted: TrendRecord/TrendInput gain it; addTrend conditional-spread,
first-sight kept on re-capture (no back-fill). SCHEMA_VERSION 1→2 with a lossless
forward migrate-on-load: Math.max(onDisk, current) + numeric-typeof coercion
(string/NaN/absent → current; non-array trends coercion preserved verbatim)
- `capture` CLI: stdin raw item|batch → normalize → bridge → addTrend → saveStore once;
tally {added,duplicates,merged,errors} from AddResult; content-invalid → errors[],
exit 2 only on bad stdin; --json summary
- wiring: trend-spotter.md Step 4.5 N×`add` → one normalizing `capture` batch; README
add/capture framing corrected; test-runner Section 16h (capture wiring, unconditional)
+ floors bumped (trends 62→79, ASSERT 87→90)
TDD: 17 new tests (12 genuinely-RED logic-RED + 5 regression guards), tsc clean,
gate 105/0/0. No version bump (additive, v0.5.2 dev).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VmHCQjJHUyWwxGAVVjNLgp
This commit is contained in:
parent
b4e500fad4
commit
7a158030b6
10 changed files with 465 additions and 31 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { describe, test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { normalizeItem, normalizeItems } from "../src/item.js";
|
||||
import { normalizeItem, normalizeItems, itemToInput } from "../src/item.js";
|
||||
import { normalizeField } from "../src/store.js";
|
||||
|
||||
describe("trends item normalizer (RE-R1 / B1)", () => {
|
||||
|
|
@ -179,4 +179,49 @@ describe("trends item normalizer (RE-R1 / B1)", () => {
|
|||
assert.deepEqual(errors, []);
|
||||
});
|
||||
});
|
||||
|
||||
describe("itemToInput — bridge to the store input (RE-R2a / B-bridge)", () => {
|
||||
// Build a realistic envelope via the normalizer (the actual upstream path).
|
||||
const mkItem = (extra: Record<string, unknown> = {}) => {
|
||||
const r = normalizeItem({
|
||||
source: "tavily",
|
||||
title: "OpenAI ships a reasoning model",
|
||||
url: "https://example.com/Article",
|
||||
topics: ["ai", "reasoning"],
|
||||
summary: "A short summary.",
|
||||
...extra,
|
||||
});
|
||||
assert.equal(r.ok, true);
|
||||
if (!r.ok) throw new Error("fixture item failed to normalize");
|
||||
return r.item;
|
||||
};
|
||||
|
||||
test("injects capturedAt and carries source/title/url/topics/summary/publishedAt verbatim", () => {
|
||||
const input = itemToInput(mkItem({ publishedAt: "2026-06-20" }), "2026-06-24");
|
||||
assert.equal(input.capturedAt, "2026-06-24");
|
||||
assert.equal(input.source, "tavily");
|
||||
assert.equal(input.title, "OpenAI ships a reasoning model");
|
||||
assert.equal(input.url, "https://example.com/Article");
|
||||
assert.deepEqual(input.topics, ["ai", "reasoning"]);
|
||||
assert.equal(input.summary, "A short summary.");
|
||||
assert.equal(input.publishedAt, "2026-06-20");
|
||||
});
|
||||
|
||||
test("derives NO id (the store owns id via addTrend->trendId)", () => {
|
||||
const input = itemToInput(mkItem(), "2026-06-24") as Record<string, unknown>;
|
||||
assert.equal("id" in input, false);
|
||||
});
|
||||
|
||||
test("an item without publishedAt -> input omits the key (not undefined-valued)", () => {
|
||||
const input = itemToInput(mkItem(), "2026-06-24"); // mkItem carries no publishedAt
|
||||
assert.equal("publishedAt" in input, false);
|
||||
});
|
||||
|
||||
test("field-confusion guard: capturedAt (injected) is distinct from publishedAt (carried)", () => {
|
||||
const input = itemToInput(mkItem({ publishedAt: "2026-06-20" }), "2026-06-24");
|
||||
assert.notEqual(input.capturedAt, input.publishedAt);
|
||||
assert.equal(input.publishedAt, "2026-06-20");
|
||||
assert.equal(input.capturedAt, "2026-06-24");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue