Skip to content

Commit dadfd55

Browse files
fix: use --sfdx-url-file for Windows CI auth, add test_session cleanup
Replace stdin-based auth with temp file + --sfdx-url-file for reliable cross-platform behavior (stdin and flag order fail on Windows). Add root-level after() hook to remove leftover test_session_* directories. Made-with: Cursor
1 parent 42caa0f commit dadfd55

2 files changed

Lines changed: 60 additions & 8 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2026, Salesforce, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { readdirSync, rmSync } from 'node:fs';
18+
import { join } from 'node:path';
19+
20+
/**
21+
* Root-level cleanup: remove any test_session_* directories left behind.
22+
*
23+
* TestSession.clean() normally deletes these, but they can persist when:
24+
* - rm fails (e.g. Windows file locks from spawned processes)
25+
* - Process is killed before after() runs (timeout, SIGKILL)
26+
* - TESTKIT_SAVE_ARTIFACTS is set
27+
*
28+
* This hook runs after all NUTs complete as a fallback.
29+
*/
30+
after(() => {
31+
const cwd = process.cwd();
32+
try {
33+
for (const name of readdirSync(cwd)) {
34+
if (name.startsWith('test_session_')) {
35+
try {
36+
rmSync(join(cwd, name), { recursive: true, force: true });
37+
} catch {
38+
/* ignore per-dir failures */
39+
}
40+
}
41+
}
42+
} catch {
43+
/* ignore */
44+
}
45+
});

test/commands/webapp/helpers/webappProjectUtils.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616

1717
import { execSync } from 'node:child_process';
18-
import { mkdirSync, writeFileSync } from 'node:fs';
18+
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
1919
import { join } from 'node:path';
20+
import { tmpdir } from 'node:os';
2021
import type { TestSession } from '@salesforce/cli-plugins-testkit';
2122

2223
/**
@@ -48,13 +49,19 @@ export function authOrgViaUrl(): string {
4849
throw new Error('TESTKIT_AUTH_URL environment variable is not set.');
4950
}
5051

51-
const output = execSync('sf org login sfdx-url --sfdx-url-stdin --json', {
52-
input: authUrl,
53-
stdio: ['pipe', 'pipe', 'pipe'],
54-
}).toString();
55-
56-
const result = JSON.parse(output) as { result: { username: string } };
57-
return result.result.username;
52+
// Use --sfdx-url-file instead of stdin for cross-platform reliability
53+
// (stdin can fail on Windows; --sfdx-url-stdin must be last flag)
54+
const tmpFile = join(tmpdir(), `testkit-auth-${Date.now()}-${Math.random().toString(36).slice(2)}.txt`);
55+
try {
56+
writeFileSync(tmpFile, authUrl, 'utf8');
57+
const output = execSync(`sf org login sfdx-url --sfdx-url-file "${tmpFile}" --json`, {
58+
stdio: 'pipe',
59+
}).toString();
60+
const result = JSON.parse(output) as { result: { username: string } };
61+
return result.result.username;
62+
} finally {
63+
rmSync(tmpFile, { force: true });
64+
}
5865
}
5966

6067
/**

0 commit comments

Comments
 (0)