Skip to content

Commit a473de1

Browse files
CopilotlpcoxCopilotgithub-advanced-security[bot]
authored
Fix BYOK smoke workflow COPILOT_MODEL fallback override in postprocessing (#2049)
* Initial plan * fix: enforce non-empty COPILOT_MODEL fallback in BYOK smoke postprocess Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/de450c36-9674-4ba2-9fa8-4fbf7d96f0af * Update scripts/ci/postprocess-smoke-workflows.test.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update scripts/ci/postprocess-smoke-workflows.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Syntax error' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Syntax error' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Landon Cox <landon.cox@microsoft.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent f2739d9 commit a473de1

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

scripts/ci/postprocess-smoke-workflows.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ const sessionStateDirInjectionRegex =
245245
const copySessionStateStepRegex =
246246
/^(\s+)- name: Copy Copilot session state files to logs\n\1 if: always\(\)\n\1 continue-on-error: true\n\1 run: bash "\$\{RUNNER_TEMP\}\/gh-aw\/actions\/copy_copilot_session_state\.sh"\n/m;
247247

248+
const copilotModelEmptyFallbackRegex =
249+
/(COPILOT_MODEL:\s*\$\{\{\s*vars\.GH_AW_MODEL_AGENT_COPILOT\s*\|\|\s*)''(\s*\}\})/g;
250+
248251
function buildCopySessionStateStep(indent: string): string {
249252
const i = indent;
250253
const ri = `${i} `;
@@ -355,3 +358,31 @@ describe('buildCopySessionStateStep', () => {
355358
});
356359
});
357360

361+
describe('copilotModelEmptyFallbackRegex', () => {
362+
const EXPECTED_COPILOT_MODEL_FALLBACK = 'claude-opus-4.6';
363+
364+
beforeEach(() => {
365+
copilotModelEmptyFallbackRegex.lastIndex = 0;
366+
});
367+
368+
it('should replace empty fallback with claude-opus-4.6 fallback', () => {
369+
const input = " COPILOT_MODEL: ${{ vars.GH_AW_MODEL_AGENT_COPILOT || '' }}\n";
370+
const result = input.replace(
371+
copilotModelEmptyFallbackRegex,
372+
`$1'${EXPECTED_COPILOT_MODEL_FALLBACK}'$2`
373+
);
374+
expect(result).toBe(
375+
` COPILOT_MODEL: \${{ vars.GH_AW_MODEL_AGENT_COPILOT || '${EXPECTED_COPILOT_MODEL_FALLBACK}' }}\n`
376+
);
377+
});
378+
379+
it('should not modify already-correct fallback', () => {
380+
const input =
381+
" COPILOT_MODEL: ${{ vars.GH_AW_MODEL_AGENT_COPILOT || 'claude-opus-4.6' }}\n";
382+
const result = input.replace(
383+
copilotModelEmptyFallbackRegex,
384+
`$1'${EXPECTED_COPILOT_MODEL_FALLBACK}'$2`
385+
);
386+
expect(result).toBe(input);
387+
});
388+
});

scripts/ci/postprocess-smoke-workflows.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ const sessionStateDirInjectionRegex =
9494
/--audit-dir \/tmp\/gh-aw\/sandbox\/firewall\/audit(?! --session-state-dir)/g;
9595
const SESSION_STATE_DIR = '/tmp/gh-aw/sandbox/agent/session-state';
9696

97+
// Work around gh-aw compiler bug (gh-aw#26565) where Copilot model fallback is
98+
// emitted as an empty string:
99+
// COPILOT_MODEL: ${{ vars.GH_AW_MODEL_AGENT_COPILOT || '' }}
100+
// In BYOK smoke workflows, this overrides workflow-level COPILOT_MODEL when the
101+
// repo variable is unset, causing Copilot CLI startup failure.
102+
const copilotModelEmptyFallbackRegex =
103+
/(COPILOT_MODEL:\s*\$\{\{\s*vars\.GH_AW_MODEL_AGENT_COPILOT\s*\|\|\s*)''(\s*\}\})/g;
104+
97105
// Sentinel used to detect whether the "Copy Copilot session state" step has
98106
// already been replaced with the AWF-aware inline script.
99107
const copySessionStateSentinel = 'SESSION_STATE_SRC=';
@@ -445,6 +453,24 @@ for (const workflowPath of workflowPaths) {
445453
}
446454
}
447455

456+
// For smoke-copilot-byok: replace empty model fallbacks with the workflow-
457+
// level COPILOT_MODEL env so the generated step inherits the shared default
458+
// without hardcoding a duplicate model string here.
459+
const isCopilotByokSmoke = workflowPath.includes('smoke-copilot-byok.lock.yml');
460+
if (isCopilotByokSmoke) {
461+
const emptyFallbackMatches = content.match(copilotModelEmptyFallbackRegex);
462+
if (emptyFallbackMatches) {
463+
content = content.replace(
464+
copilotModelEmptyFallbackRegex,
465+
'$1env.COPILOT_MODEL$2'
466+
);
467+
modified = true;
468+
console.log(
469+
` Replaced ${emptyFallbackMatches.length} empty COPILOT_MODEL fallback(s) for BYOK smoke`
470+
);
471+
}
472+
}
473+
448474
// For smoke-services: inject GitHub Actions services block (Redis + PostgreSQL) into the
449475
// agent job and replace --enable-host-access with --allow-host-service-ports 6379,5432.
450476
// The gh-aw compiler does not natively support GitHub Actions `services:` in the

0 commit comments

Comments
 (0)