Skip to content

refactor: extract pure YouTube ingest formatting into server/lib/youtubeIngestFormat.js - #6132

Merged
atomantic merged 1 commit into
mainfrom
claim/issue-6015
Sep 3, 2026
Merged

refactor: extract pure YouTube ingest formatting into server/lib/youtubeIngestFormat.js#6132
atomantic merged 1 commit into
mainfrom
claim/issue-6015

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

Pure-extraction refactor of the brain's YouTube ingest. server/services/youtubeIngest.js had grown to 865 lines mixing six responsibilities, so unit-testing YAML frontmatter escaping or the CoS agent prompt required importing the whole service graph (child process, brain/cos/media stores, fs) behind eight vi.mock stubs.

Moved the pure half verbatim into a new server/lib/youtubeIngestFormat.js:

The service imports them and keeps orchestration, storage, and the yt-dlp spawn. No fs / db / childProcess / SSE imports in the new module.

Behavior preservation: the seven moved bodies are byte-identical to the originals (verified by diffing each extracted function against origin/main's copy). The only edits were doc-comment wording where a comment described the old location ("Pure + exported so…").

Barrel wiring: surfaced as a namespace export (youtubeIngestFormat.*) rather than flat — formatDuration collides with fileCore.js and sanitizeFilename with mimeTypes.js, which index.test.js's collision guard rejects for flat export *. Catalog row added to server/lib/README.md.

Tests: the four public contracts move to server/lib/youtubeIngestFormat.test.js, which now runs with zero mocks — a standing check that nothing impure leaks back into lib/. server/services/youtubeIngest.test.js keeps the URL-allowlist and cancel-escalation cases (and drops six now-unneeded mocks' worth of justification). Added one case that pins the untrusted-transcript notice in the agent prompt, which nothing covered before.

Test plan

  • cd server && npm test — full server suite: 1918 files passed / 1 skipped, 38707 tests passed / 14 skipped
  • Targeted: npm test -- lib/youtubeIngestFormat.test.js services/youtubeIngest.test.js lib/index.test.js — 27 passed (barrel/README parity + collision guard included)

Closes #6015

https://claude.ai/code/session_01RA3pD5YM2dukQwbZ3pC6WA

`server/services/youtubeIngest.js` mixed six responsibilities in one 865-line
file, so unit-testing YAML escaping or the CoS agent prompt meant importing the
whole service graph (child process, brain/cos/media stores, fs) behind a wall of
`vi.mock` stubs.

Move the pure half — `parseVideoMetadata`, `buildIngestNote`,
`buildAgentTaskContext`, `resolveObsidianPointer`, `sanitizeFilename`,
`formatDuration`, `yamlString` — verbatim into the new
`server/lib/youtubeIngestFormat.js`. The moved bodies are byte-identical; the
service imports them and keeps orchestration, storage, and the yt-dlp spawn.

The new module is surfaced through the `server/lib` barrel as a NAMESPACE export
(`youtubeIngestFormat.*`) rather than a flat one: `formatDuration` collides with
`fileCore.js` and `sanitizeFilename` with `mimeTypes.js`, which the barrel's
collision guard rejects for flat `export *`.

Tests for those four public contracts move to
`server/lib/youtubeIngestFormat.test.js` and now run with no mocks at all — if
that file ever needs one, something impure leaked back into lib/. The service
suite keeps the URL-allowlist and cancel-escalation cases. Added coverage for
the untrusted-transcript boundary notice in the agent prompt, which nothing
pinned before.

Claude-Session: https://claude.ai/code/session_01RA3pD5YM2dukQwbZ3pC6WA
@atomantic
atomantic merged commit 21e261e into main Sep 3, 2026
7 checks passed
@atomantic
atomantic deleted the claim/issue-6015 branch September 3, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split pure prompt formatting and metadata parsing out of server/services/youtubeIngest.js into server/lib/youtubeIngestFormat.js

1 participant