Skip to content

fix: make YAML-relative cwd resolution opt-in - #43

Merged
kjgbot merged 1 commit into
mainfrom
fix/cwd-yaml-relative-0825
Aug 25, 2026
Merged

fix: make YAML-relative cwd resolution opt-in#43
kjgbot merged 1 commit into
mainfrom
fix/cwd-yaml-relative-0825

Conversation

@miyaontherelay

Copy link
Copy Markdown
Contributor

Summary

  • add workflow-level cwdResolution: "workflow-file" | "process"
  • preserve the current process-relative behavior by default
  • resolve agent and step cwd from the YAML directory only when explicitly opted in
  • warn on omitted configuration whenever process-relative and YAML-relative paths differ, including both resolved paths and the future-major flip
  • align TypeScript and JSON schema documentation with the actual behavior

This PR is stacked on ci/pr-test-gate-0825 so pull-request CI covers it. It should be retargeted to main after PR #42 merges.

Release note

Workflows can now opt into YAML-file-relative agent and step working directories with cwdResolution: workflow-file; use cwdResolution: process to pin the legacy behavior. The default remains process-relative in this release, but ambiguous omitted configurations emit a deprecation warning and will flip in a future major. This prevents a silent path mismatch seen by the Native design partner, where cwd: .. selected an unrelated 5.9GB directory and increased a tick from 115k tokens to 326k tokens.

Which execution paths do these tests cover?

  • Parsed YAML file + cwdResolution: workflow-file: both agent cwd and step cwd resolve from the YAML parent directory.
  • Explicit cwdResolution: process: both agent and step paths retain runner/process-relative behavior.
  • Omitted cwdResolution: the compatibility warning includes the concrete current and future paths plus the future-major default flip.
  • Full core suite covers execute/dry-run consumers of the resolver; the focused test directly covers the parsed-file resolution path.

A green suite proves the paths that have tests, and nothing else.

Verification

  • focused step-cwd.test.ts: exit 0, 6/6 tests
  • npm test: exit 0, 951/951 tests
  • npm run typecheck: exit 0

Session-Id: 01a037bb-4e8c-7c20-8962-621515f5e335
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e7944d3b-23ac-46ab-a37d-004f376d517e

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3 issues found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="packages/core/src/__tests__/step-cwd.test.ts">

<violation number="1" location="packages/core/src/__tests__/step-cwd.test.ts:174">
P3: warn.mockRestore() runs only on the success path. If an assertion fails, the console.warn spy leaks into the rest of the suite and silently swallows warnings from later tests. Wrap the spy registration and assertions in try/finally, or restore the spy after each test.</violation>
</file>

<file name="packages/core/src/runner.ts">

<violation number="1" location="packages/core/src/runner.ts:3052">
P2: After a runner parses a YAML file, parsing a string config leaves the previous `workflowFileDir` in place, so `cwdResolution: workflow-file` resolves against the wrong file. Clear `workflowFileDir` when the source is not an absolute YAML path before configuring the mode.</violation>
</file>

<file name="packages/core/src/schema.json">

<violation number="1" location="packages/core/src/schema.json:845">
P3: WorktreeWorkflowStep, IntegrationWorkflowStep and WaitForWorkflowStep do not declare `cwd` and set additionalProperties: false, yet the runtime (resolveEffectiveCwd) and the WorkflowStep type (schema.ts) support `cwd` on those step types too. A worktree/integration/waitFor step with `cwd` is valid and honored at runtime but flagged invalid by JSON-Schema editor validation. Add `cwd` to those three step definitions to keep the schema aligned with the resolver and the shared WorkflowStep type.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment on lines +3052 to +3054
if (source !== '<string>' && path.isAbsolute(source)) {
this.workflowFileDir = path.dirname(source);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: After a runner parses a YAML file, parsing a string config leaves the previous workflowFileDir in place, so cwdResolution: workflow-file resolves against the wrong file. Clear workflowFileDir when the source is not an absolute YAML path before configuring the mode.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/src/runner.ts, line 3052:

<comment>After a runner parses a YAML file, parsing a string config leaves the previous `workflowFileDir` in place, so `cwdResolution: workflow-file` resolves against the wrong file. Clear `workflowFileDir` when the source is not an absolute YAML path before configuring the mode.</comment>

<file context>
@@ -2997,11 +3043,15 @@ export class WorkflowRunner {
 
   /** Parse a relay.yaml string. */
   parseYamlString(raw: string, source = '<string>'): RelayYamlConfig {
+    if (source !== '<string>' && path.isAbsolute(source)) {
+      this.workflowFileDir = path.dirname(source);
+    }
</file context>
Suggested change
if (source !== '<string>' && path.isAbsolute(source)) {
this.workflowFileDir = path.dirname(source);
}
this.workflowFileDir = source !== '<string>' && path.isAbsolute(source) ? path.dirname(source) : undefined;

const workflowDir = '/workflow/config';
const runner = new WorkflowRunner({ cwd: runnerRoot });
(runner as any).workflowFileDir = workflowDir;
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: warn.mockRestore() runs only on the success path. If an assertion fails, the console.warn spy leaks into the rest of the suite and silently swallows warnings from later tests. Wrap the spy registration and assertions in try/finally, or restore the spy after each test.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/src/__tests__/step-cwd.test.ts, line 174:

<comment>warn.mockRestore() runs only on the success path. If an assertion fails, the console.warn spy leaks into the rest of the suite and silently swallows warnings from later tests. Wrap the spy registration and assertions in try/finally, or restore the spy after each test.</comment>

<file context>
@@ -83,4 +106,82 @@ describe('WorkflowRunner step cwd resolution', () => {
+    const workflowDir = '/workflow/config';
+    const runner = new WorkflowRunner({ cwd: runnerRoot });
+    (runner as any).workflowFileDir = workflowDir;
+    const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+
+    (runner as any).configureCwdResolution(config());
</file context>

"type": "string",
"description": "Sets this step's working directory to a named entry from the top-level paths array."
},
"cwd": {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: WorktreeWorkflowStep, IntegrationWorkflowStep and WaitForWorkflowStep do not declare cwd and set additionalProperties: false, yet the runtime (resolveEffectiveCwd) and the WorkflowStep type (schema.ts) support cwd on those step types too. A worktree/integration/waitFor step with cwd is valid and honored at runtime but flagged invalid by JSON-Schema editor validation. Add cwd to those three step definitions to keep the schema aligned with the resolver and the shared WorkflowStep type.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/core/src/schema.json, line 845:

<comment>WorktreeWorkflowStep, IntegrationWorkflowStep and WaitForWorkflowStep do not declare `cwd` and set additionalProperties: false, yet the runtime (resolveEffectiveCwd) and the WorkflowStep type (schema.ts) support `cwd` on those step types too. A worktree/integration/waitFor step with `cwd` is valid and honored at runtime but flagged invalid by JSON-Schema editor validation. Add `cwd` to those three step definitions to keep the schema aligned with the resolver and the shared WorkflowStep type.</comment>

<file context>
@@ -836,6 +842,10 @@
           "type": "string",
           "description": "Sets this step's working directory to a named entry from the top-level paths array."
         },
+        "cwd": {
+          "type": "string",
+          "description": "Working directory for this step, resolved according to the top-level cwdResolution setting."
</file context>

@kjgbot
kjgbot deleted the branch main August 25, 2026 12:42
@kjgbot kjgbot closed this Aug 25, 2026
@kjgbot kjgbot reopened this Aug 25, 2026
@kjgbot
kjgbot changed the base branch from ci/pr-test-gate-0825 to main August 25, 2026 12:43
@kjgbot
kjgbot merged commit 56ece6d into main Aug 25, 2026
4 checks passed
@kjgbot
kjgbot deleted the fix/cwd-yaml-relative-0825 branch August 25, 2026 12:44
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.

2 participants