Skip to content

feat(session-3-block-3): GET /api/product endpoint + product.yaml real#3

Merged
lhpaul merged 5 commits into
developfrom
feature/session-3-block-3-product-endpoint
May 14, 2026
Merged

feat(session-3-block-3): GET /api/product endpoint + product.yaml real#3
lhpaul merged 5 commits into
developfrom
feature/session-3-block-3-product-endpoint

Conversation

@lhpaul
Copy link
Copy Markdown
Owner

@lhpaul lhpaul commented May 14, 2026

Summary

Wires @helm/shared's parseProductConfigFromFile into the API, adds E2E config loading from the knowledge repo, and creates the first real .helm/product.yaml in lhpaul/helm-knowledge (committed separately to that repo's main).

4 commits:

  • refactor(@helm/shared): preserve fs error codes in parseProductConfigFromFileProductConfigError gains code?: string; parseProductConfigFromFile passes fsErr.code so callers check err.code === 'ENOENT' directly without inspecting cause. More robust than string-matching the message.

  • feat(@helm/api): add GET /api/product endpoint loading config from knowledge repo — Splits app.ts (HTTP routes, testable in Node.js/Vitest) from index.ts (Bun server + WS wiring). GET /api/product reads HELM_KNOWLEDGE_REPO_PATH env var, loads {path}/.helm/product.yaml via parseProductConfigFromFile, returns 200/404/500 with typed JSON errors. 4 tests using app.request().

  • chore(@helm/api): add .env.example for HELM_KNOWLEDGE_REPO_PATH — Documents that .env lives in apps/api/ (not root) because Bun reads from process CWD.

  • docs: add 'Configuración local' section to AGENT.md — Documents per-package .env convention, lists HELM_KNOWLEDGE_REPO_PATH as first required var.

Test plan

  • pnpm turbo run test → 30/30 (4 api + 14 storage + 12 shared)
  • pnpm turbo run build → 4/4, tsc --noEmit clean, api bundles 134 modules
  • pnpm turbo run lint → 4/4, 0 errors
  • E2E: HELM_KNOWLEDGE_REPO_PATH=/Users/lhpaul/Git/Helm/helm-knowledge pnpm dev + curl :3001/api/product → 200 with Helm Product JSON (verified after PR)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Health check endpoint reporting status and uptime.
    • Product configuration endpoint to read product settings from a local knowledge repo.
  • Documentation

    • Local development guide updated with env var setup and how to configure the local knowledge repo path.
  • Tests

    • Added tests covering product endpoint behavior (valid, missing, invalid config, unset env).
  • Bug Fixes / Improvements

    • Configuration parser preserves filesystem error codes on failures; test runner script enabled.

Review Change Stack

lhpaul and others added 4 commits May 14, 2026 15:04
…FromFile

ProductConfigError gains an optional code?: string constructor parameter.
parseProductConfigFromFile passes fsErr.code when wrapping the fs exception,
so callers can do err.code === 'ENOENT' without reaching into err.cause.

This is more robust than message-string matching — the code property is
stable regardless of message wording changes in the parser.

Test updated: now asserts err.code === 'ENOENT' in addition to instanceof
and message checks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…owledge repo

Splits app.ts (HTTP routes, testable in Node.js) from index.ts (Bun server
wiring + WS). Tests import app.ts directly without pulling in hono/bun.

GET /api/product:
- 500 if HELM_KNOWLEDGE_REPO_PATH is not set
- reads {HELM_KNOWLEDGE_REPO_PATH}/.helm/product.yaml via parseProductConfigFromFile
- 404 if file missing (detected via err.code === 'ENOENT', not string matching)
- 500 with field path if schema is invalid (ProductConfigError message)
- 200 + Product JSON on success

4 tests using app.request() (no server spin-up):
valid config → 200, missing file → 404, invalid schema → 500+field path,
missing env var → 500. beforeEach/afterEach snapshot+restore process.env.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents the env var required by GET /api/product.
Lives in apps/api/ (not root) because Bun reads .env from the process CWD,
which is apps/api/ when Turbo runs the dev server.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Documents where .env files live (apps/api/.env, not root) and why —
Bun reads .env from the process CWD which is apps/api/ when Turbo runs.
Prevents future agents/humans from looking for .env in the wrong place.
Lists HELM_KNOWLEDGE_REPO_PATH as the first required server variable.
Updates helm-knowledge reference (no longer 'próximamente').

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 58d050ff-fb27-4686-b1a0-f7e11b8f7367

📥 Commits

Reviewing files that changed from the base of the PR and between 590ed29 and da26740.

📒 Files selected for processing (1)
  • apps/api/src/routes/product.ts

📝 Walkthrough

Walkthrough

This PR adds a /api/product endpoint that reads Helm knowledge repository configuration, refactors API app initialization for testability, enhances error handling to preserve filesystem error codes, and documents local development configuration via environment variables and setup instructions.

Changes

Product Endpoint and Local Development

Layer / File(s) Summary
Error code preservation in ProductConfigError
packages/shared/src/config/product-parser.ts, packages/shared/src/config/product-parser.test.ts
ProductConfigError gains an optional code property to preserve filesystem error codes from failed file reads; tests assert the preserved err.code (e.g., ENOENT).
App initialization and health endpoint
apps/api/src/app.ts, apps/api/src/index.ts
Hono app instance is exported from app.ts with a /health route; index.ts imports app and retains Bun WebSocket wiring to avoid importing hono/bun in tests.
Product endpoint with config file parsing and tests
apps/api/src/routes/product.ts, apps/api/src/routes/product.test.ts
Adds GET /api/product which reads ${HELM_KNOWLEDGE_REPO_PATH}/.helm/product.yaml, parses it, maps ENOENT→404, returns parser errors as 500, and includes tests for success, missing file, schema errors, and missing env var.
Local development configuration and test setup
AGENT.md, apps/api/.env.example, apps/api/package.json
Documents local env setup and Helm knowledge repo path in AGENT.md, adds apps/api/.env.example with HELM_KNOWLEDGE_REPO_PATH, and updates the API test script to run vitest.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • lhpaul/helm#1: Both PRs modify the shared product config parsing layer—packages/shared/src/config/product-parser.ts (ProductConfigError and parseProductConfigFromFile)—with this PR extending the parser to preserve filesystem error codes.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main changes: adding a GET /api/product endpoint and integrating real product.yaml configuration files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/session-3-block-3-product-endpoint

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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 `@apps/api/src/routes/product.ts`:
- Around line 21-23: The error handling currently returns the absolute
configPath to clients (in the ENOENT branch), leaking host paths; instead, keep
the absolute path in server logs (e.g., console.error or your logger) and return
a stable relative location or friendly message to the client. Update the ENOENT
branch that references configPath so it logs the full configPath server-side
(using console.error or processLogger) and change the c.json response to a fixed
relative identifier such as "product.yaml in config directory" or
"config/product.yaml" without including configPath; keep references to
configPath only in logs and not in the HTTP response.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c547625e-52a5-421e-8810-ed6f47e4c896

📥 Commits

Reviewing files that changed from the base of the PR and between 1632f7f and 590ed29.

📒 Files selected for processing (9)
  • AGENT.md
  • apps/api/.env.example
  • apps/api/package.json
  • apps/api/src/app.ts
  • apps/api/src/index.ts
  • apps/api/src/routes/product.test.ts
  • apps/api/src/routes/product.ts
  • packages/shared/src/config/product-parser.test.ts
  • packages/shared/src/config/product-parser.ts

Comment thread apps/api/src/routes/product.ts
The ENOENT branch was returning configPath (absolute host filesystem path)
to the HTTP client. Server-side debug info is kept via console.error; the
client now receives a stable relative identifier instead:
  '$HELM_KNOWLEDGE_REPO_PATH/.helm/product.yaml'

Test assertions already matched on substrings ('not found', '.helm/product.yaml')
so no test changes required.

Addresses CodeRabbit review comment on PR #3.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lhpaul lhpaul merged commit 9600ae5 into develop May 14, 2026
1 check passed
@lhpaul lhpaul deleted the feature/session-3-block-3-product-endpoint branch May 14, 2026 20:57
lhpaul added a commit that referenced this pull request May 14, 2026
…response

POST /api/items was forwarding err.message directly to the client on
product config load failure, which could expose filesystem paths from
ProductConfigError ('Cannot read file: /path/...').

Now logs the full error server-side with console.error and returns the
generic 'Failed to load product config' message — consistent with the
path-leak fix applied to /api/product in PR #3.

Test updated: no longer checks for 'HELM_KNOWLEDGE_REPO_PATH' in the
response body; checks for the generic message instead.

Addresses CodeRabbit review comment on PR #6.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant