Skip to content

fix(compile): remove empty env block from executor step when no write permissions#407

Merged
jamesadevine merged 2 commits into
mainfrom
copilot/fix-empty-env-block-issue
May 5, 2026
Merged

fix(compile): remove empty env block from executor step when no write permissions#407
jamesadevine merged 2 commits into
mainfrom
copilot/fix-empty-env-block-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Summary

When permissions.write is absent, the "Execute safe outputs (Stage 3)" bash step emitted a bare env: key with no children — invalid ADO pipeline YAML.

Root cause: generate_executor_ado_env returned an empty string, but the templates unconditionally wrapped it in an env: key, producing:

        env:
          # ← nothing here → invalid

Fix:

  • generate_executor_ado_env — returns the full env: block when a write service connection is set, empty string otherwise. replace_with_indent handles base-indentation alignment automatically:
    Some(_) => "env:\n  SYSTEM_ACCESSTOKEN: $(SC_WRITE_TOKEN)".to_string(),
    None => String::new(),
  • base.yml / 1es-base.yml — removed the bare env: line; {{ executor_ado_env }} is now the sole marker on that line.
  • docs/template-markers.md — updated to document that {{ executor_ado_env }} now emits the entire block or nothing.

Test plan

  • Updated unit tests for generate_executor_ado_env to assert the env: key is included in the non-empty output.
  • Two new integration tests in compiler_tests.rs:
    • test_executor_step_no_empty_env_block_without_write_permissions — compiles minimal-agent.md (no write perms), asserts no env: key is present on the executor step. Note: a bare env: with no children is valid YAML (parsed as null), so assert_valid_yaml alone does not catch this regression — the structural !executor_step_text.contains("env:") assertion is what guards against it.
    • test_executor_step_has_env_block_with_write_permissions — compiles complete-agent.md (with write perms), asserts SYSTEM_ACCESSTOKEN: $(SC_WRITE_TOKEN) appears under the executor step.

… permissions

Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/e4d2855e-c0f7-4fc9-8214-5b9942c995dd

Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
@jamesadevine
Copy link
Copy Markdown
Collaborator

/rust-review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Rust PR Reviewer completed successfully!

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

🔍 Rust PR Review

Summary: Looks good — correct fix, well-tested, one misleading test comment worth noting.

Findings

⚠️ Suggestions

  • tests/compiler_tests.rs:3493 — The comment "serde_yaml rejects env: with no children in strict mode and the assert_valid_yaml call above already exercises this" is incorrect. env: null (bare env: key with no children) is valid YAML and serde_yaml will parse it without error. The assert_valid_yaml call does not catch this case. The structural assertion that follows (!executor_step_text.contains("env:")) is what actually validates the fix. The comment should be removed or corrected to avoid misleading future contributors.

✅ What Looks Good

  • replace_with_indent interaction is correct: The function correctly handles the multiline "env:\n SYSTEM_ACCESSTOKEN: $(SC_WRITE_TOKEN)" replacement — the env: key gets the template's base indentation, and subsequent lines get base_indent + " ", producing correctly-structured YAML for both base.yml (8-space indent) and 1es-base.yml (18-space indent).
  • Empty-string case is clean: When None, the replacement is "" which replace_with_indent handles by leaving a whitespace-only line — valid YAML, no env: null artifact.
  • Tests are well-scoped: The two new integration tests clearly cover both the absent and present write-permissions cases, and the find("- bash:") bounding approach is reliable for these fixtures.
  • Doc update is accurate: docs/template-markers.md correctly describes the new contract ("emits the entire block or nothing").

Generated by Rust PR Reviewer for issue #407 · ● 493.2K ·

@jamesadevine
Copy link
Copy Markdown
Collaborator

@copilot tests/compiler_tests.rs:3493 — The comment "serde_yaml rejects env: with no children in strict mode and the assert_valid_yaml call above already exercises this" is incorrect. env: null (bare env: key with no children) is valid YAML and serde_yaml will parse it without error. The assert_valid_yaml call does not catch this case. The structural assertion that follows (!executor_step_text.contains("env:")) is what actually validates the fix. The comment should be removed or corrected to avoid misleading future contributors.

…validity

Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/42b1fb99-3470-483e-acc3-99d1f8299528

Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

@copilot tests/compiler_tests.rs:3493 — The comment "serde_yaml rejects env: with no children in strict mode and the assert_valid_yaml call above already exercises this" is incorrect. env: null (bar...

Fixed in 69ab847. The comment now correctly states that a bare env: is valid YAML (parsed as null) and assert_valid_yaml would not catch the regression — the !executor_step_text.contains("env:") assertion is what actually guards against it.

Copilot AI requested a review from jamesadevine May 5, 2026 15:13
@jamesadevine jamesadevine merged commit 0f25f06 into main May 5, 2026
15 checks passed
@jamesadevine jamesadevine deleted the copilot/fix-empty-env-block-issue branch May 5, 2026 15:17
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