feat(api): accept suffixed sections in schemas, parse worker, PATCH, filenames#116
Conversation
… PRs, TDD task breakdown
…no more base truncation
…tion collided distinct sections
…e normalized, 400 on malformed
… not a job-killing section
safeFilename now allows '.' in the section part so '26 00 13.10' renders as '26-00-13.10-Panelboards.docx' rather than mangling the dot to a dash. Function exported for unit testing.
…CX title Regression pins — no production change. Verifies that renderMarkdown emits the section verbatim in the H1 header and that generateDocx writes it unchanged into document.xml, so future refactors cannot silently mangle dotted agency suffixes (e.g. '27 05 13.43').
…RCHITECTURE examples
📝 WalkthroughWalkthroughThis PR expands CSI section number format support to include dotted and agency suffixes. The codebase now validates, preserves, and normalizes section values like ChangesSection Format Expansion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ARCHITECTURE.md (1)
347-347: 💤 Low valueConsider adding the agency suffix example for consistency.
Lines 228 and 265 document all three expanded section formats (basic, dotted suffix, and agency suffix), but this comment only shows two examples. Adding
"01 32 01.00 10"or similar would maintain consistency across all three section-related schema comments.📝 Suggested addition
- target_spec_section VARCHAR(20), -- "09 91 00" / "26 00 13.10" — for section refs + target_spec_section VARCHAR(20), -- "09 91 00" / "26 00 13.10" / "01 32 01.00 10" — for section refs🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ARCHITECTURE.md` at line 347, The comment for target_spec_section (the column definition containing "09 91 00" / "26 00 13.10") is missing the agency-suffix example; update the inline schema comment for target_spec_section to include a third example showing an agency suffix (e.g., "01 32 01.00 10") so it matches the expanded formats documented elsewhere (lines that show basic, dotted suffix, and agency suffix formats).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/api/parse.ts`:
- Around line 68-79: Update the /parse handler to validate the incoming req.body
with a Zod schema using safeParse before calling parseBody: define a zod object
that enforces title and section (if present) are strings (or optional strings),
call schema.safeParse(req.body) and if it fails return res.status(400).json({
success: false, error: ... }) immediately; only after successful validation call
parseBody(req.body) to produce rawBody and then proceed with
normalizeSectionNumber and creation of the ParseBody object (referencing
parseBody, rawBody, normalizeSectionNumber, ParseBody, req, and res).
---
Nitpick comments:
In `@ARCHITECTURE.md`:
- Line 347: The comment for target_spec_section (the column definition
containing "09 91 00" / "26 00 13.10") is missing the agency-suffix example;
update the inline schema comment for target_spec_section to include a third
example showing an agency suffix (e.g., "01 32 01.00 10") so it matches the
expanded formats documented elsewhere (lines that show basic, dotted suffix, and
agency suffix formats).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 144f123a-583e-40f2-9dae-6bc6d12a2a89
📒 Files selected for processing (12)
ARCHITECTURE.mdsrc/api/generate.test.tssrc/api/generate.tssrc/api/parse.test.tssrc/api/parse.tssrc/api/specs.integration.test.tssrc/ast/schemas.test.tssrc/ast/schemas.tssrc/generator/index.test.tssrc/generator/markdown.test.tssrc/parser/docx/index.test.tssrc/parser/docx/index.ts
…now 400 instead of silent drop
Summary
Stacked on the parsers PR. Closes the API-side gates:
ast/schemas:SpecTreeSchema.sectionaccepts expanded shapes or the'unknown'parser sentinel;PatchSpecBodySchemaaccepts expanded shapes only — PATCH /specs/:id no longer 422s legitimate suffixed sections, and clients cannot write the sentinel.api/parse: worker-output schema gated to expanded-shape-or-'unknown'(closes the parse-vs-PATCH inconsistency); the optional bodysectionoverride is normalized, with 400 on malformed input before job creation; section-gate job failures surface a friendly message instead of a Zod JSON blob.parser/docx: free-textdc:subjectmetadata degrades to'unknown'(content inference takes over) instead of poisoning the gated tree.api/generate: download filename preserves the dot —26-00-13.10-….docx.NN NN NN-only ARCHITECTURE.md examples refreshed.Test Plan
pnpm test— 579 unit tests green at this commitdocker compose up -d postgres && cp -n .env.example .env; set -a && source .env && set +a && pnpm migrate && pnpm seed && pnpm test:integration— PATCH accepts27 21 00.10and27 21 00.10 20over HTTP;'27210'still 422sOut of Scope
This PR does NOT touch the DB layer — normalization migration, CHECK constraints, and seed hardening land in PR 4. The MCP/file-loader direct-persist paths remain backstopped only after PR 4's CHECK constraints.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation