Skip to content

Commit 1e85efc

Browse files
jamesadevineCopilot
andcommitted
refactor(compile): remove indent parameter from generate_awf_mounts
Move {{ awf_mounts }} to its own template line so replace_with_indent handles indentation automatically. When no mounts exist, emit a bare bash continuation marker (\) to preserve the surrounding \-chain. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d7f3055 commit 1e85efc

6 files changed

Lines changed: 23 additions & 25 deletions

File tree

docs/template-markers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ The output is formatted as a comma-separated string (e.g., `github.com,*.dev.azu
369369

370370
Replaced with `--mount` flags for the **agent job** AWF invocation only (not the detection job), collected from `CompilerExtension::required_awf_mounts()`. Each extension can declare volume mounts needed inside the AWF chroot as [`AwfMount`][AwfMount] values (e.g., the Lean runtime mounts `$HOME/.elan` so the elan toolchain is accessible).
371371

372-
When no extensions declare mounts, this is replaced with an empty string (no `--mount` flags). When mounts are present, each is formatted as `--mount "spec" \` on its own continuation line (followed by a newline and appropriate indentation for the next AWF flag).
372+
When no extensions declare mounts, this is replaced with `\` (a bare bash continuation marker) so the surrounding `\`-continuation chain is preserved. When mounts are present, each is formatted as `--mount "spec" \` on its own line; indentation is handled by `replace_with_indent` at the call site.
373373

374374
AWF replaces `$HOME` with an empty directory overlay for security; only explicitly mounted subdirectories are accessible inside the chroot. Shell variables like `$HOME` are expanded at runtime by bash.
375375

src/compile/common.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,32 +1678,26 @@ pub fn generate_allowed_domains(
16781678
/// Each mount spec is rendered using its [`Display`][std::fmt::Display] impl
16791679
/// (Docker bind-mount format: `host_path:container_path[:mode]`).
16801680
///
1681-
/// Returns an empty string if no extensions require mounts.
1682-
/// When mounts are present, each flag occupies its own continuation line:
1683-
/// `--mount "spec" \` followed by a newline and `indent`, ready to precede
1684-
/// the next AWF flag inline in the template.
1685-
///
1686-
/// `indent` should match the whitespace that precedes sibling AWF flags in
1687-
/// the template (e.g. `" "` for standalone, `" "`
1688-
/// for 1ES).
1689-
pub fn generate_awf_mounts(
1690-
extensions: &[super::extensions::Extension],
1691-
indent: &str,
1692-
) -> String {
1681+
/// When no extensions require mounts, returns `\` (a bare bash continuation
1682+
/// marker) so the surrounding `\`-continuation chain in the template is
1683+
/// preserved. When mounts are present, each flag occupies its own line
1684+
/// (`--mount "spec" \`); indentation is handled by [`replace_with_indent`]
1685+
/// at the call site.
1686+
pub fn generate_awf_mounts(extensions: &[super::extensions::Extension]) -> String {
16931687
let mounts: Vec<super::extensions::AwfMount> = extensions
16941688
.iter()
16951689
.flat_map(|ext| ext.required_awf_mounts())
16961690
.collect();
16971691

16981692
if mounts.is_empty() {
1699-
return String::new();
1693+
return "\\".to_string();
17001694
}
17011695

17021696
mounts
17031697
.iter()
1704-
.map(|m| format!("--mount \"{}\" \\\n{}", m, indent))
1698+
.map(|m| format!("--mount \"{}\" \\", m))
17051699
.collect::<Vec<_>>()
1706-
.join("")
1700+
.join("\n")
17071701
}
17081702

17091703
// ==================== Shared compile flow ====================
@@ -3761,8 +3755,8 @@ mod tests {
37613755
fn test_generate_awf_mounts_no_extensions() {
37623756
let fm = minimal_front_matter();
37633757
let exts = crate::compile::extensions::collect_extensions(&fm);
3764-
let result = generate_awf_mounts(&exts, " ");
3765-
assert!(result.is_empty(), "no mounts without lean");
3758+
let result = generate_awf_mounts(&exts);
3759+
assert_eq!(result, "\\", "no mounts should produce bare continuation");
37663760
}
37673761

37683762
#[test]
@@ -3771,12 +3765,14 @@ mod tests {
37713765
"---\nname: test\ndescription: test\nruntimes:\n lean: true\n---\n",
37723766
).unwrap();
37733767
let exts = crate::compile::extensions::collect_extensions(&fm);
3774-
let result = generate_awf_mounts(&exts, " ");
3768+
let result = generate_awf_mounts(&exts);
37753769
assert!(result.contains("--mount"), "should contain --mount flag");
37763770
assert!(result.contains(".elan"), "should reference .elan directory");
37773771
assert!(result.contains(":ro"), "should be read-only");
3778-
// Each mount ends with ` \` continuation and newline+indent
3779-
assert!(result.contains("\\\n "), "mount should be its own continuation line");
3772+
// Each mount line ends with ` \` continuation
3773+
assert!(result.ends_with(" \\"), "last mount should end with continuation");
3774+
// No embedded indent — replace_with_indent handles indentation
3775+
assert!(!result.contains(" "), "should not contain hard-coded indent");
37803776
}
37813777

37823778
// ═══════════════════════════════════════════════════════════════════════

src/compile/onees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Compiler for OneESCompiler {
5050

5151
// Generate values shared with standalone that are passed as extra replacements
5252
let allowed_domains = generate_allowed_domains(front_matter, &extensions)?;
53-
let awf_mounts = generate_awf_mounts(&extensions, " ");
53+
let awf_mounts = generate_awf_mounts(&extensions);
5454
let enabled_tools_args = generate_enabled_tools_args(front_matter);
5555

5656
let mcpg_config = generate_mcpg_config(front_matter, &ctx, &extensions)?;

src/compile/standalone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Compiler for StandaloneCompiler {
5151

5252
// Standalone-specific values
5353
let allowed_domains = generate_allowed_domains(front_matter, &extensions)?;
54-
let awf_mounts = generate_awf_mounts(&extensions, " ");
54+
let awf_mounts = generate_awf_mounts(&extensions);
5555
let enabled_tools_args = generate_enabled_tools_args(front_matter);
5656

5757
let config_obj = generate_mcpg_config(front_matter, &ctx, &extensions)?;

src/data/1es-base.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ extends:
339339
--skip-pull \
340340
--env-all \
341341
--enable-host-access \
342-
{{ awf_mounts }}--container-workdir "{{ working_directory }}" \
342+
{{ awf_mounts }}
343+
--container-workdir "{{ working_directory }}" \
343344
--log-level info \
344345
--proxy-logs-dir "$(Agent.TempDirectory)/staging/logs/firewall" \
345346
-- '{{ engine_run }}' \

src/data/base.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ jobs:
310310
--skip-pull \
311311
--env-all \
312312
--enable-host-access \
313-
{{ awf_mounts }}--container-workdir "{{ working_directory }}" \
313+
{{ awf_mounts }}
314+
--container-workdir "{{ working_directory }}" \
314315
--log-level info \
315316
--proxy-logs-dir "$(Agent.TempDirectory)/staging/logs/firewall" \
316317
-- '{{ engine_run }}' \

0 commit comments

Comments
 (0)