Skip to content

Commit 1aeafb9

Browse files
jamesadevineCopilot
andcommitted
refactor(compile): drop unused ADO_AW_IMPORT_BASE env var
`import.js` consults `ADO_AW_IMPORT_BASE` only when resolving a relative marker path (`isAbsolute(rawPath) ? rawPath : resolve(base, rawPath)`). In the pipeline the only marker `import.js` ever sees is the compiler-generated top-level body marker, which embeds an absolute `\/…` path. The resolver is also single-pass by design, so author-written nested relative markers inside the inlined body are never re-expanded at runtime. The env var was therefore dead code at runtime. Changes: - Remove the `env:` block from `resolver_step()` in `src/compile/extensions/ado_script.rs` (and update its unit test to assert the variable is **absent**). - Drop the `process.env.ADO_AW_IMPORT_BASE ??` fallback in `scripts/ado-script/src/import/index.ts`; `import.js` now always uses `dirname(argv[2])` for relative-path resolution (irrelevant in pipeline use, useful for local invocations). - Replace the `ADO_AW_IMPORT_BASE`-override vitest with a `dirname(target)` default-base test that pins the fallback for standalone callers. - Update `docs/ado-script.md` and `docs/runtime-imports.md` to drop the env-var contract and explain why the runtime never sees a relative marker. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent baf94f5 commit 1aeafb9

5 files changed

Lines changed: 29 additions & 25 deletions

File tree

docs/ado-script.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ syntax.
4545

4646
### Env-var contract
4747

48-
| Env var | Required | Purpose |
49-
|---|---|---|
50-
| `ADO_AW_IMPORT_BASE` | No | Base directory for relative imports. Defaults to `dirname(argv[2])`. |
48+
`import.js` takes no environment variables. Relative-path markers
49+
resolve against `dirname(argv[2])`; in pipeline use this is irrelevant
50+
because the compiler always embeds an absolute marker path and
51+
`import.js` is single-pass (nested markers inside the inlined body are
52+
not re-expanded).
5153

5254
The bundle lives at `dist/import/index.js` and ships in the same
5355
`ado-script.zip` release asset as `gate.js`, so pipelines download it

docs/runtime-imports.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ along with any author-written markers.
3636

3737
## Path resolution
3838

39-
- **Absolute paths** are used as-is.
40-
- **Relative paths at runtime** are resolved against the `ADO_AW_IMPORT_BASE`
41-
environment variable. For user-facing imports, the compiler sets this to
42-
`{{ trigger_repo_directory }}`.
39+
- **Absolute paths** are used as-is. The compiler always emits an
40+
absolute marker path for the agent body itself (`$(Build.SourcesDirectory)/…`)
41+
so the resolver step never has to resolve a relative path at runtime.
4342
- **Relative paths at compile time** (`inlined-imports: true`) are resolved
4443
against the source `.md` file's directory.
4544

scripts/ado-script/src/import/__tests__/path-resolution.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { resolve } from "node:path";
21
import { describe, expect, it } from "vitest";
32
import { readText, runImportSource, withScratchDir, writeFixture } from "./helpers.js";
43

@@ -19,21 +18,23 @@ describe("runtime-import path resolution", () => {
1918
});
2019
});
2120

22-
it("resolves relative paths against ADO_AW_IMPORT_BASE when set", () => {
23-
withScratchDir("base-override", (dir) => {
24-
writeFixture(dir, "imports/nested/snippet.md", "OVERRIDE\n");
21+
it("resolves relative paths against dirname(target)", () => {
22+
// The compiler always emits an absolute marker path, so this branch
23+
// is unreachable in pipeline use. The test pins the fallback so a
24+
// standalone invocation of `import.js` (e.g. local dev or future
25+
// callers) behaves predictably.
26+
withScratchDir("relative-default-base", (dir) => {
27+
writeFixture(dir, "snippet.md", "SIBLING\n");
2528
const target = writeFixture(
2629
dir,
27-
"prompt/prompt.md",
28-
"start\n{{#runtime-import nested/snippet.md}}\nend\n",
30+
"prompt.md",
31+
"start\n{{#runtime-import ./snippet.md}}\nend\n",
2932
);
3033

31-
const result = runImportSource(target, {
32-
ADO_AW_IMPORT_BASE: resolve(dir, "imports"),
33-
});
34+
const result = runImportSource(target);
3435

3536
expect(result.status).toBe(0);
36-
expect(readText(target)).toBe("start\nOVERRIDE\n\nend\n");
37+
expect(readText(target)).toBe("start\nSIBLING\n\nend\n");
3738
});
3839
});
3940
});

scripts/ado-script/src/import/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function main(): void {
3131
fail([`target file not found: ${sanitizeForVsoMessage(target)}`]);
3232
}
3333

34-
const base = process.env.ADO_AW_IMPORT_BASE ?? dirname(target);
34+
const base = dirname(target);
3535
const original = readFileSync(target, "utf8");
3636
const errors: string[] = [];
3737

src/compile/extensions/ado_script.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,16 @@ fn install_and_download_steps() -> Vec<String> {
100100
/// The resolver step that runs in the Agent job to expand
101101
/// `{{#runtime-import …}}` markers in the agent prompt file in place.
102102
///
103-
/// `ADO_AW_IMPORT_BASE` is `$(Build.SourcesDirectory)` so that
104-
/// author-written relative imports (e.g.
105-
/// `{{#runtime-import shared/snippet.md}}`) resolve against the trigger
106-
/// repo's checkout root — matching gh-aw's path-resolution semantics.
103+
/// The compiler always emits an absolute marker path (built from
104+
/// `$(Build.SourcesDirectory)` plus the repo-relative source path) and
105+
/// the resolver is single-pass, so relative-path resolution never
106+
/// happens in practice; `import.js` falls back to `dirname(target)` for
107+
/// the unreachable relative-path case.
107108
fn resolver_step() -> String {
108109
format!(
109110
r#"- bash: |
110111
set -eo pipefail
111112
node '{IMPORT_EVAL_PATH}' /tmp/awf-tools/agent-prompt.md
112-
env:
113-
ADO_AW_IMPORT_BASE: $(Build.SourcesDirectory)
114113
displayName: "Resolve runtime imports (agent prompt)"
115114
condition: succeeded()"#
116115
)
@@ -368,7 +367,10 @@ mod tests {
368367
assert!(steps[1].contains("Download ado-aw scripts"));
369368
assert!(steps[2].contains("node '/tmp/ado-aw-scripts/ado-script/dist/import/index.js'"));
370369
assert!(steps[2].contains("Resolve runtime imports (agent prompt)"));
371-
assert!(steps[2].contains("ADO_AW_IMPORT_BASE: $(Build.SourcesDirectory)"));
370+
assert!(
371+
!steps[2].contains("ADO_AW_IMPORT_BASE"),
372+
"resolver step must not export ADO_AW_IMPORT_BASE — the compiler emits absolute marker paths and import.js is single-pass, so the env var would never be consulted"
373+
);
372374
}
373375

374376
#[test]

0 commit comments

Comments
 (0)