Skip to content

feat: test config initial runtime values setup#177

Merged
MihalyToth20 merged 6 commits intomainfrom
dev
Nov 28, 2025
Merged

feat: test config initial runtime values setup#177
MihalyToth20 merged 6 commits intomainfrom
dev

Conversation

@MihalyToth20
Copy link
Copy Markdown
Collaborator

@MihalyToth20 MihalyToth20 commented Nov 28, 2025

  • now it's possible to pass in initial runtimeValues for the test config, This is useful when running tests that involve secrets, like test passwords etc.
  • fixed in issue with repo generation from local workspace.yaml file

Summary by CodeRabbit

  • New Features

    • Added --test-env CLI option to inject environment variables into test runs.
    • Introduced formatted test results summary with detailed error reporting.
  • Bug Fixes

    • Enhanced error handling for file write operations during generation with per-file status tracking.
  • Chores

    • Updated GitHub workflow permissions for release process.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 28, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce environment variable injection for tests via a new --test-env CLI option, threading these values through the test runner chain. The repo generation command now includes per-file write error handling and conditional config resolution. A workflow permission is updated to allow content writes.

Changes

Cohort / File(s) Summary
GitHub Workflow Permissions
.github/workflows/release.yml
Updated permissions block to change contents from read to write while maintaining id-token as write.
Test Environment Variable Injection
packages/cli/src/commands/test/index.ts, packages/cli/src/commands/test/implementation/test.ts, packages/core/src/features/testing/index.ts, packages/core/src/implementations/run-tests.ts, packages/core/src/index.ts
Added new --test-env CLI option for passing environment variables (KEY=VALUE pairs) to tests. Introduced collectInitialRuntimeValues() helper to merge XANO_*-prefixed env vars from process.env with CLI-provided values. Added printTestSummary() to render formatted test results. Threaded initialRuntimeValues parameter through test runner chain: CLI → runTest → runTestsImplementation → testRunner → runtimeValues initialization.
Repository Generation Error Handling
packages/cli/src/commands/generate/implementation/repo.ts
Added per-file try-catch wrapping for write operations, capturing success/error status for each file. Introduced conditional config resolution: when input is provided and fetch is false, fabricates minimal configs instead of calling resolveConfigs(). Added write summary log reporting failed writes or success message.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • packages/cli/src/commands/test/implementation/test.ts — Review new collectInitialRuntimeValues() and printTestSummary() logic for correctness and env var precedence handling
  • packages/cli/src/commands/generate/implementation/repo.ts — Examine conditional config resolution logic (input + !fetch branch) and per-file error capture to ensure writes don't silently fail
  • packages/cli/src/commands/test/index.ts — Verify --test-env option parsing converts KEY=VALUE pairs correctly into the cliTestEnvVars object

Possibly related PRs

Poem

🐰 Environment vars hop through the stack,
From CLI to core and back,
Per-file errors caught with care,
Tests now flourish everywhere! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the primary feature addition: enabling initial runtime values for test configuration, which is the main functional objective across multiple files.

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.

Copy link
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (4)
packages/cli/src/commands/generate/implementation/repo.ts (1)

119-144: Consider using log.error for write failures.

While the per-file error handling is well-implemented, line 140-141 uses log.warn for write failures. Since these failures prevent generated files from being written, consider using log.error instead for clearer severity indication.

Apply this diff:

    if (failedWrites.length) {
-      log.warn(`Some files failed to write (${failedWrites.length}):`);
-      failedWrites.forEach((r) => log.warn(` - ${r.path}: ${r.error}`));
+      log.error(`Some files failed to write (${failedWrites.length}):`);
+      failedWrites.forEach((r) => log.error(` - ${r.path}: ${r.error}`));
    } else {
       log.info('All files written successfully.');
    }
packages/core/src/index.ts (1)

335-366: Consider making initialRuntimeValues optional for backward compatibility.

The new initialRuntimeValues parameter is currently required, which could break existing callers of the public API. Since the testRunner already handles this with a fallback (initialRuntimeValues ?? {}), consider making it optional here as well.

Apply this diff:

   async runTests({
      context,
      groups,
      testConfig,
-     initialRuntimeValues,
+     initialRuntimeValues = {},
   }: {
      context: Context;
      groups: ApiGroupConfig[];
      testConfig: any;
-     initialRuntimeValues: Record<string, any>;
+     initialRuntimeValues?: Record<string, any>;
   }): Promise<
packages/cli/src/commands/test/implementation/test.ts (2)

12-32: Clarify misleading comment about key format.

The comment at line 15 states "returns flat object with ENVIRONMENT.* keys", but the function actually returns keys as-is (e.g., XANO_PASSWORD). While the implementation is correct for use with the {{ENVIRONMENT.KEY}} template pattern in test configs, the comment could be clearer.

Apply this diff:

 /**
  *
  * @param cliEnvVars - object of CLI provided env vars (e.g., {DEMO_ADMIN_PWD: 'xyz'})
- * @returns flat object with ENVIRONMENT.* keys
+ * @returns flat object with keys as-is, to be used with {{ENVIRONMENT.KEY}} template pattern
  */

27-31: Simplify unnecessary loop.

Lines 27-31 create a new object by copying all entries from merged without any transformation. You can directly return merged instead.

Apply this diff:

-   const result = {};
-   for (const [k, v] of Object.entries(merged)) {
-      result[`${k}`] = v;
-   }
-   return result;
+   return merged;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8da6e and f55bdfd.

📒 Files selected for processing (7)
  • .github/workflows/release.yml (1 hunks)
  • packages/cli/src/commands/generate/implementation/repo.ts (2 hunks)
  • packages/cli/src/commands/test/implementation/test.ts (6 hunks)
  • packages/cli/src/commands/test/index.ts (2 hunks)
  • packages/core/src/features/testing/index.ts (4 hunks)
  • packages/core/src/implementations/run-tests.ts (3 hunks)
  • packages/core/src/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/core/src/implementations/run-tests.ts (1)
packages/core/src/features/testing/index.ts (1)
  • testRunner (264-264)
packages/cli/src/commands/test/index.ts (1)
packages/cli/src/utils/methods/with-error-handler.ts (1)
  • withErrorHandler (24-43)
🔇 Additional comments (7)
.github/workflows/release.yml (1)

10-12: LGTM: Appropriate permissions for automated releases.

The contents: write permission enables the changesets action to commit release changes back to the repository, which is standard practice for automated release workflows.

packages/cli/src/commands/test/index.ts (1)

35-43: LGTM: Robust parsing of environment variables.

The parsing logic correctly handles edge cases including:

  • Values containing = characters (line 40 joins with =)
  • Empty keys (line 39 validates key exists)
  • Missing values (line 39 checks rest.length > 0)
packages/core/src/implementations/run-tests.ts (1)

5-41: LGTM: Clean parameter threading.

The initialRuntimeValues parameter is correctly added to the function signature, type annotation, and forwarded to testRunner without introducing any behavioral changes.

packages/core/src/features/testing/index.ts (1)

64-114: LGTM: Proper initialization of runtime values.

The initialization logic correctly uses nullish coalescing to provide a fallback empty object, and subsequent test execution can augment these values (lines 230-233) as expected.

packages/cli/src/commands/test/implementation/test.ts (2)

47-130: LGTM: Well-structured test summary formatting.

The summary table provides comprehensive test results with appropriate detail levels. The dynamic column width calculation ensures clean formatting regardless of content length.


170-230: LGTM: Clean integration of runtime values collection.

The function correctly collects initial runtime values from both environment variables and CLI arguments, then passes them to the test runner at the appropriate point in the execution flow.

packages/cli/src/commands/generate/implementation/repo.ts (1)

59-74: The review comment's concern is unfounded—the code is safe as written.

The dummy configs are created only when input && !fetch is true (line 61). When fetch is true, the condition evaluates to false and resolveConfigs is called instead, which provides all required fields including url. The subsequent if (fetch) block at line 91 that accesses instanceConfig.url is only reached when resolveConfigs provides complete configs. The two paths are mutually exclusive—there is no scenario where dummy configs (which lack url) would be used with code that accesses url.

The dummy configs contain all fields they actually need for their intended use case:

  • instanceConfig.name, process.output ✓ (used at lines 81, 79—both accessible via either path)
  • workspaceConfig.name, id ✓ (used at lines 82, 95—line 95 only in if(fetch) block)
  • branchConfig.label ✓ (used at lines 83, 96—line 96 only in if(fetch) block)

No validation changes are needed.

@MihalyToth20 MihalyToth20 merged commit dc55056 into main Nov 28, 2025
2 checks passed
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