test: config — ConfigPaths.parseText substitution and JSONC parsing#391
test: config — ConfigPaths.parseText substitution and JSONC parsing#391anandgupta42 wants to merge 1 commit intomainfrom
Conversation
…overage
ConfigPaths.parseText handles {env:VAR} and {file:path} substitutions in config
files plus JSONC parsing with error reporting. Zero tests existed. New coverage
mitigates risk of silent config loading failures affecting all users.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
https://claude.ai/code/session_01LAyJZEAuipia1v9DZjbDCo
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA new Bun test suite was added for Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Merges 9 test PRs (#390, #394, #395, #396, #397, #398, #399, #401, #387) into a single PR, discarding 4 duplicates (#391, #392, #393, #400). **New test coverage:** - `id.test.ts` — 14 tests: Identifier generation, monotonic ordering, timestamp extraction, Zod schema - `shell.test.ts` — 9 tests: shell blacklist enforcement for fish/nu, cache reset, fallback - `path-traversal.test.ts` — 7 tests (new): `Protected.isSensitiveWrite` for .pem/.key, .gnupg, .env variants - `ignore.test.ts` — 7 tests (new): `FileIgnore.match` directory patterns, globs, whitelist overrides - `paths-parsetext.test.ts` — 16 tests: `ConfigPaths.parseText` env/file substitution, JSONC parsing - `finops-formatting.test.ts` — 14 tests: `formatBytes`/`truncateQuery` edge cases - `finops-role-access.test.ts` — 10 tests: RBAC `formatGrants`/`formatHierarchy`/`formatUserRoles` - `tool-lookup.test.ts` — 4 tests: Zod schema introspection for tool parameters - `summary-git-path.test.ts` — 10 tests: `unquoteGitPath` decoding for non-ASCII filenames - `tracing.test.ts` — 2 tests (added): Recap loop detection boundaries - `patch.test.ts` — 9 tests (added): `maybeParseApplyPatchVerified` entry point coverage - `instruction.test.ts` — 13 tests (new): `InstructionPrompt.loaded()` dedup guards - `message-v2.test.ts` — 23 tests (new): `MessageV2.filterCompacted()` boundary detection **Bug fixes (discovered during testing):** - `finops-formatting.ts`: fix `formatBytes` crash on negative/NaN/fractional inputs - `finops-formatting.ts`: fix `truncateQuery` returning empty for whitespace-only, exceeding `maxLen` when < 4 - `training-import.test.ts`: fix pre-existing typecheck errors (missing `context`/`rule` mock keys) - `instruction.test.ts`, `message-v2.test.ts`: fix `MessageV2.Part` cast and branded ID type errors Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Consolidated into #403 |
* test: consolidated test coverage across 9 modules (133 new tests) Merges 9 test PRs (#390, #394, #395, #396, #397, #398, #399, #401, #387) into a single PR, discarding 4 duplicates (#391, #392, #393, #400). **New test coverage:** - `id.test.ts` — 14 tests: Identifier generation, monotonic ordering, timestamp extraction, Zod schema - `shell.test.ts` — 9 tests: shell blacklist enforcement for fish/nu, cache reset, fallback - `path-traversal.test.ts` — 7 tests (new): `Protected.isSensitiveWrite` for .pem/.key, .gnupg, .env variants - `ignore.test.ts` — 7 tests (new): `FileIgnore.match` directory patterns, globs, whitelist overrides - `paths-parsetext.test.ts` — 16 tests: `ConfigPaths.parseText` env/file substitution, JSONC parsing - `finops-formatting.test.ts` — 14 tests: `formatBytes`/`truncateQuery` edge cases - `finops-role-access.test.ts` — 10 tests: RBAC `formatGrants`/`formatHierarchy`/`formatUserRoles` - `tool-lookup.test.ts` — 4 tests: Zod schema introspection for tool parameters - `summary-git-path.test.ts` — 10 tests: `unquoteGitPath` decoding for non-ASCII filenames - `tracing.test.ts` — 2 tests (added): Recap loop detection boundaries - `patch.test.ts` — 9 tests (added): `maybeParseApplyPatchVerified` entry point coverage - `instruction.test.ts` — 13 tests (new): `InstructionPrompt.loaded()` dedup guards - `message-v2.test.ts` — 23 tests (new): `MessageV2.filterCompacted()` boundary detection **Bug fixes (discovered during testing):** - `finops-formatting.ts`: fix `formatBytes` crash on negative/NaN/fractional inputs - `finops-formatting.ts`: fix `truncateQuery` returning empty for whitespace-only, exceeding `maxLen` when < 4 - `training-import.test.ts`: fix pre-existing typecheck errors (missing `context`/`rule` mock keys) - `instruction.test.ts`, `message-v2.test.ts`: fix `MessageV2.Part` cast and branded ID type errors Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address code review findings — test artifact leakage and cleanup - summary-git-path.test.ts: use tmpdir() instead of projectRoot to prevent Storage.write() from polluting the developer's .opencode/storage/ directory - finops-role-access.test.ts: consolidate duplicate afterAll hooks to ensure ALTIMATE_TELEMETRY_DISABLED env var is cleaned up after tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
What does this PR do?\n\n1.
ConfigPaths.parseTextandConfigPaths.substitute—src/config/paths.ts(11 new tests)\n\nThis module handles all config file loading:{env:VAR}token substitution,{file:path}file inclusion, and JSONC parsing with error reporting. Zero tests existed. This is the core config loading path — any bug here crashes the application or silently produces wrong config values for every user.\n\nNew coverage includes:\n\n**{env:VAR}substitution (2 tests):\n- Happy path: environment variable value is correctly interpolated into config\n- Missing env var: silently resolves to empty string (documents surprising behavior — a typo in var name produces no error)\n\n{file:path}substitution (5 tests):\n- Relative path resolution:{file:secret.txt}resolves relative to the config file's directory, not CWD\n- Absolute path:{file:/abs/path}bypasses relative resolution viapath.isAbsolute()branch\n- Whitespace trimming: file content is.trim()'d — prevents trailing newlines from corrupting API keys\n- Missing file error: throwsConfigInvalidErrorwith "does not exist" message pointing to the resolved path\n- Missing file with\"empty\"mode: gracefully returns empty string instead of throwing (used for optional file refs)\n- Comment awareness:{file:...}tokens inside//comment lines are skipped, preventing errors from documented example configs\n\nJSONC parsing (2 tests):**\n- Valid JSONC: comments and trailing commas parse correctly (validatesjsonc-parserwiring)\n- Syntax error reporting:ConfigJsonErrorincludes the file path, line/column numbers, and the full JSONC input for debugging\n- Error echo: the problematic input text is included in the error message so users can identify the issue\n\n### Type of change\n- [x] New feature (non-breaking change which adds functionality)\n\n### Issue for this PR\nN/A — proactive test coverage.ConfigPaths.parseTexthad zero tests despite being the config loading critical path.\n\n### How did you verify your code works?\n\n\nbun test test/config/paths.test.ts # 11 pass, 0 fail (287ms)\n\n\nTests were reviewed by a critic agent that:\n- Rejected 4 tests (duplicate code paths, trivially correct code)\n- Caught a critical bug: assertions usederr.propertiesinstead oferr.data(would have silently passed while asserting nothing)\n- Approved 9 tests, 2 revised with theerr.datafix\n\n### Checklist\n- [x] I have added tests that prove my fix is effective or that my feature works\n- [x] New and existing unit tests pass locally with my changes\n\nhttps://claude.ai/code/session_01LAyJZEAuipia1v9DZjbDCoSummary by CodeRabbit