Skip to content

test: config — ConfigPaths.parseText substitution and JSONC parsing#391

Closed
anandgupta42 wants to merge 1 commit intomainfrom
claude/test-config-paths-20260323-session_01LAyJZEAuipia1v9DZjbDCo
Closed

test: config — ConfigPaths.parseText substitution and JSONC parsing#391
anandgupta42 wants to merge 1 commit intomainfrom
claude/test-config-paths-20260323-session_01LAyJZEAuipia1v9DZjbDCo

Conversation

@anandgupta42
Copy link
Contributor

@anandgupta42 anandgupta42 commented Mar 23, 2026

What does this PR do?\n\n1. ConfigPaths.parseText and ConfigPaths.substitutesrc/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 via path.isAbsolute() branch\n- Whitespace trimming: file content is .trim()'d — prevents trailing newlines from corrupting API keys\n- Missing file error: throws ConfigInvalidError with "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 (validates jsonc-parser wiring)\n- Syntax error reporting: ConfigJsonError includes 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.parseText had 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 used err.properties instead of err.data (would have silently passed while asserting nothing)\n- Approved 9 tests, 2 revised with the err.data fix\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_01LAyJZEAuipia1v9DZjbDCo

Summary by CodeRabbit

  • Tests
    • Added comprehensive test coverage for configuration path parsing, including environment variable substitution, file inclusion handling, and JSONC validation with robust error detection.

…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
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 23, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 795af954-5bc8-46c5-926c-7f798a05884c

📥 Commits

Reviewing files that changed from the base of the PR and between 8eb13d4 and 905608f.

📒 Files selected for processing (1)
  • packages/opencode/test/config/paths.test.ts

📝 Walkthrough

Walkthrough

A new Bun test suite was added for ConfigPaths.parseText that verifies environment variable substitution ({env:VAR}), file content substitution ({file:path}), JSONC parsing with comments and trailing commas, error handling for missing files and invalid JSONC, and behavior of substitution patterns within comments.

Changes

Cohort / File(s) Summary
ConfigPaths Test Suite
packages/opencode/test/config/paths.test.ts
Added comprehensive test coverage for parseText method including environment variable and file substitution, JSONC parsing validation, error handling for missing files and invalid JSONC with structured error details, and comment-context handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

contributor

Poem

🐰 A test suite hops in with care,
Checking vars and files everywhere,
JSONC comments skip unread,
Errors caught with data spread—
Config paths now safely tread! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding tests for ConfigPaths.parseText substitution and JSONC parsing.
Description check ✅ Passed The description covers all required template sections with substantial detail: Summary explains what changed and why, Test Plan documents verification with command and results, and Checklist items are completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 claude/test-config-paths-20260323-session_01LAyJZEAuipia1v9DZjbDCo

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.

❤️ Share

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

anandgupta42 added a commit that referenced this pull request Mar 23, 2026
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>
@anandgupta42
Copy link
Contributor Author

Consolidated into #403

@anandgupta42 anandgupta42 deleted the claude/test-config-paths-20260323-session_01LAyJZEAuipia1v9DZjbDCo branch March 23, 2026 17:11
anandgupta42 added a commit that referenced this pull request Mar 23, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant