Skip to content

Commit 31164d7

Browse files
authored
[WIP] Align shared steps in 1ES and standalone templates (#52)
1 parent b8d8ece commit 31164d7

4 files changed

Lines changed: 80 additions & 12 deletions

File tree

src/compile/common.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,6 @@ pub const AWF_VERSION: &str = "0.23.1";
465465
/// See: https://pkgs.dev.azure.com/msazuresphere/_packaging/Guardian1ESPTUpstreamOrgFeed/nuget/v3/index.json
466466
pub const COPILOT_CLI_VERSION: &str = "1.0.6";
467467

468-
/// Version of the Agency CLI (agency.linux-x64) NuGet package to install in 1ES pipelines.
469-
/// Update this when upgrading to a new Agency CLI release.
470-
/// See: https://pkgs.dev.azure.com/msazuresphere/_packaging/Guardian1ESPTUpstreamOrgFeed/nuget/v3/index.json
471-
pub const AGENCY_CLI_VERSION: &str = "2026.1.22.4";
472-
473468
/// Generate source path for the execute command.
474469
///
475470
/// Returns a path using `{{ workspace }}` as the base, which gets resolved

src/compile/onees.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::path::Path;
1717

1818
use super::Compiler;
1919
use super::common::{
20-
self, AGENCY_CLI_VERSION, AWF_VERSION, DEFAULT_POOL, compute_effective_workspace, generate_copilot_params,
20+
self, AWF_VERSION, COPILOT_CLI_VERSION, DEFAULT_POOL, compute_effective_workspace, generate_copilot_params,
2121
generate_acquire_ado_token, generate_checkout_self, generate_checkout_steps,
2222
generate_ci_trigger, generate_copilot_ado_env, generate_executor_ado_env,
2323
generate_pipeline_path, generate_pipeline_resources, generate_pr_trigger,
@@ -139,7 +139,7 @@ displayName: "Finalize""#,
139139
("{{ compiler_version }}", compiler_version),
140140
// No-op for 1ES (template doesn't use AWF), but included for forward-compatibility
141141
("{{ firewall_version }}", AWF_VERSION),
142-
("{{ agency_version }}", AGENCY_CLI_VERSION),
142+
("{{ copilot_version }}", COPILOT_CLI_VERSION),
143143
("{{ pool }}", &pool),
144144
("{{ schedule }}", &schedule),
145145
("{{ pr_trigger }}", &pr_trigger),
@@ -163,6 +163,7 @@ displayName: "Finalize""#,
163163
("{{ source_path }}", &source_path),
164164
("{{ pipeline_path }}", &pipeline_path),
165165
("{{ working_directory }}", &working_directory),
166+
("{{ workspace }}", &working_directory),
166167
("{{ agency_params }}", &agency_params),
167168
("{{ acquire_ado_token }}", &acquire_read_token),
168169
("{{ copilot_ado_env }}", &copilot_ado_env),

templates/1es-base.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ extends:
159159
displayName: "Authenticate NuGet Feed"
160160

161161
- task: NuGetCommand@2
162-
displayName: "Install Agency CLI"
162+
displayName: "Install Copilot CLI"
163163
inputs:
164164
command: 'custom'
165-
arguments: 'install agency.linux-x64 -Source "https://pkgs.dev.azure.com/msazuresphere/_packaging/Guardian1ESPTUpstreamOrgFeed/nuget/v3/index.json" -Version {{ agency_version }} -OutputDirectory $(Agent.TempDirectory)/tools -ExcludeVersion -NonInteractive'
165+
arguments: 'install Microsoft.Copilot.CLI.linux-x64 -Source "https://pkgs.dev.azure.com/msazuresphere/_packaging/Guardian1ESPTUpstreamOrgFeed/nuget/v3/index.json" -Version {{ copilot_version }} -OutputDirectory $(Agent.TempDirectory)/tools -ExcludeVersion -NonInteractive'
166166

167167
- bash: |
168168
ls -la "$(Agent.TempDirectory)/tools"
169-
echo "##vso[task.prependpath]$(Agent.TempDirectory)/tools/agency.linux-x64"
170-
displayName: Add agency to PATH
169+
echo "##vso[task.prependpath]$(Agent.TempDirectory)/tools/Microsoft.Copilot.CLI.linux-x64"
170+
displayName: Add copilot to PATH
171171
172172
- bash: |
173173
COMPILER_VERSION="{{ compiler_version }}"
@@ -230,7 +230,7 @@ extends:
230230
THREAT_OUTPUT_FILE="$(Agent.TempDirectory)/threat-analysis-output.txt"
231231
232232
# Use $(cat file) like gh-aw does - the command is executed directly, not via a variable
233-
agency copilot --prompt "$(cat $(Agent.TempDirectory)/threat-analysis-prompt.md)" {{ agency_params }} > "$THREAT_OUTPUT_FILE" 2>&1
233+
copilot --prompt "$(cat $(Agent.TempDirectory)/threat-analysis-prompt.md)" {{ agency_params }} > "$THREAT_OUTPUT_FILE" 2>&1
234234
AGENT_EXIT_CODE=$?
235235
236236
echo "=== Threat Analysis Output (sanitized) ==="

tests/compiler_tests.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,75 @@ Do something.
784784

785785
let _ = fs::remove_dir_all(&temp_dir);
786786
}
787+
788+
/// Test that the 1ES fixture compiles correctly with no unreplaced markers
789+
/// and uses Copilot CLI (not Agency CLI) in custom jobs
790+
#[test]
791+
fn test_1es_compiled_output_no_unreplaced_markers() {
792+
let temp_dir = std::env::temp_dir().join(format!(
793+
"agentic-pipeline-1es-markers-{}",
794+
std::process::id()
795+
));
796+
fs::create_dir_all(&temp_dir).expect("Failed to create temp directory");
797+
798+
let fixture_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
799+
.join("tests")
800+
.join("fixtures")
801+
.join("1es-test-agent.md");
802+
803+
let output_path = temp_dir.join("1es-test-agent.yml");
804+
805+
// Run the compiler binary
806+
let binary_path = PathBuf::from(env!("CARGO_BIN_EXE_ado-aw"));
807+
let output = std::process::Command::new(&binary_path)
808+
.args([
809+
"compile",
810+
fixture_path.to_str().unwrap(),
811+
"-o",
812+
output_path.to_str().unwrap(),
813+
])
814+
.output()
815+
.expect("Failed to run compiler");
816+
817+
assert!(
818+
output.status.success(),
819+
"1ES compiler should succeed: {}",
820+
String::from_utf8_lossy(&output.stderr)
821+
);
822+
assert!(output_path.exists(), "Compiled 1ES YAML should exist");
823+
824+
let compiled = fs::read_to_string(&output_path).expect("Should read compiled YAML");
825+
826+
// Verify no unreplaced {{ markers }} remain (excluding ${{ }} which are ADO expressions)
827+
for line in compiled.lines() {
828+
let stripped = line.replace("${{", "");
829+
assert!(
830+
!stripped.contains("{{ "),
831+
"1ES compiled output should not contain unreplaced marker: {}",
832+
line.trim()
833+
);
834+
}
835+
836+
// Verify the compiler version was correctly substituted
837+
let version = env!("CARGO_PKG_VERSION");
838+
assert!(
839+
compiled.contains(version),
840+
"1ES compiled output should contain compiler version {version}"
841+
);
842+
843+
// Verify 1ES template uses Copilot CLI, not Agency CLI
844+
assert!(
845+
compiled.contains("Microsoft.Copilot.CLI.linux-x64"),
846+
"1ES template should install Copilot CLI"
847+
);
848+
assert!(
849+
!compiled.contains("install agency.linux-x64"),
850+
"1ES template should not install Agency CLI"
851+
);
852+
assert!(
853+
!compiled.contains("agency copilot"),
854+
"1ES template should not invoke 'agency copilot' command"
855+
);
856+
857+
let _ = fs::remove_dir_all(&temp_dir);
858+
}

0 commit comments

Comments
 (0)