Skip to content

Commit 40018c7

Browse files
committed
fix(ci): use cli hdiff path for e2e artifacts
1 parent bb57cd4 commit 40018c7

5 files changed

Lines changed: 48 additions & 170 deletions

File tree

‎Example/e2etest/e2e/globalSetup.ts‎

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,17 @@ function startServer() {
9797
const serverScript = path.join(projectRoot, 'scripts/local-e2e-server.ts');
9898
fs.mkdirSync(artifactsRoot, { recursive: true });
9999

100-
const logFile = path.join(artifactsRoot, '.server.log');
101-
const logFd = fs.openSync(logFile, 'w');
102-
103100
const child = spawn('bun', [serverScript], {
104101
cwd: projectRoot,
105102
detached: true,
106-
stdio: ['ignore', logFd, logFd],
103+
stdio: 'ignore',
107104
env: {
108105
...process.env,
109106
E2E_ASSET_PORT: String(LOCAL_UPDATE_PORT),
110107
},
111108
});
112109
child.unref();
113110
fs.writeFileSync(pidFile, String(child.pid));
114-
// Keep logFd open for the server lifetime — it will be cleaned up on process exit.
115111
}
116112

117113
function waitForServer(timeoutMs = 30000) {
@@ -239,27 +235,6 @@ async function globalSetup() {
239235
}
240236
startServer();
241237
await waitForServer();
242-
243-
// Diagnostic: list artifacts via debug endpoint and local filesystem
244-
const origin = `http://127.0.0.1:${LOCAL_UPDATE_PORT}`;
245-
try {
246-
const debugRes = await fetch(`${origin}/debug/artifacts`);
247-
if (debugRes.ok) {
248-
console.log('[globalSetup] Server artifacts:', await debugRes.text());
249-
} else {
250-
console.log('[globalSetup] Debug endpoint returned:', debugRes.status);
251-
}
252-
} catch (e) {
253-
console.log('[globalSetup] Debug endpoint error:', e);
254-
}
255-
const localArtifactsDir = path.join(artifactsRoot, platform);
256-
if (fs.existsSync(localArtifactsDir)) {
257-
const files = fs.readdirSync(localArtifactsDir);
258-
console.log(`[globalSetup] Local artifacts dir (${localArtifactsDir}):`, files);
259-
} else {
260-
console.log(`[globalSetup] Local artifacts dir MISSING: ${localArtifactsDir}`);
261-
}
262-
263238
await warmServer(platform as 'ios' | 'android');
264239
await detoxGlobalSetup();
265240
}

‎Example/e2etest/scripts/local-e2e-server.ts‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ const server = Bun.serve({
140140
!fs.existsSync(filePath) ||
141141
fs.statSync(filePath).isDirectory()
142142
) {
143-
console.error(
144-
`[404] ${url.pathname} -> ${filePath} (exists: ${filePath ? fs.existsSync(filePath) : 'null'})`,
145-
);
146143
return new Response('not found', { status: 404 });
147144
}
148145

@@ -159,22 +156,6 @@ const server = Bun.serve({
159156
});
160157
}
161158

162-
if (url.pathname === '/debug/artifacts') {
163-
const entries = fs.readdirSync(artifactsRoot, { recursive: true });
164-
const listing = entries.map(e => {
165-
const fullPath = path.join(artifactsRoot, String(e));
166-
try {
167-
const stat = fs.statSync(fullPath);
168-
return `${e} (${stat.size} bytes, ${stat.isDirectory() ? 'dir' : 'file'})`;
169-
} catch {
170-
return `${e} (stat failed)`;
171-
}
172-
});
173-
return new Response(JSON.stringify({ artifactsRoot, entries: listing }, null, 2), {
174-
headers: { 'Content-Type': 'application/json' },
175-
});
176-
}
177-
178159
return new Response('not found', { status: 404 });
179160
},
180161
});

‎Example/e2etest/scripts/prepare-local-update-artifacts.ts‎

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function runPushy(args: string[], cwd: string) {
6666
}
6767
const result = spawnSync('node', [cliEntry, ...args], {
6868
cwd,
69-
stdio: 'pipe',
69+
stdio: 'inherit',
7070
env: {
7171
...process.env,
7272
NODE_PATH: nodePath.join(path.delimiter),
@@ -77,12 +77,9 @@ function runPushy(args: string[], cwd: string) {
7777
timeout: 120_000,
7878
});
7979

80-
const stdout = result.stdout?.toString() ?? '';
81-
const stderr = result.stderr?.toString() ?? '';
82-
if (stdout) console.log(`[pushy ${args[0]}] stdout:`, stdout.trim());
83-
if (stderr) console.log(`[pushy ${args[0]}] stderr:`, stderr.trim());
84-
console.log(`[pushy ${args[0]}] exit code: ${result.status}, signal: ${result.signal}`);
85-
80+
if (result.error) {
81+
throw result.error;
82+
}
8683
if (result.status !== 0) {
8784
throw new Error(
8885
`pushy ${args.join(' ')} failed with exit code ${result.status}`,
@@ -126,32 +123,6 @@ function prepareDir() {
126123
fs.mkdirSync(artifactsDir, { recursive: true });
127124
}
128125

129-
function runHdiffWrapper(mode: 'ppk' | 'apk', oldFile: string, newFile: string, outputFile: string) {
130-
// Use projectRoot (source dir) not __dirname (which may be .ts-build/)
131-
const wrapperScript = path.join(projectRoot, 'scripts', 'run-hdiff-wrapper.js');
132-
console.log(`[runHdiffWrapper] script=${wrapperScript} cliRoot=${cliRoot} mode=${mode}`);
133-
console.log(`[runHdiffWrapper] args: [${cliRoot}, ${mode}, ${oldFile}, ${newFile}, ${outputFile}]`);
134-
const result = spawnSync(
135-
process.execPath,
136-
[wrapperScript, cliRoot, mode, oldFile, newFile, outputFile],
137-
{
138-
cwd: projectRoot,
139-
stdio: 'inherit',
140-
env: {
141-
...process.env,
142-
NODE_PATH: [
143-
path.join(projectRoot, 'node_modules'),
144-
path.join(cliRoot, 'node_modules'),
145-
].join(path.delimiter),
146-
},
147-
},
148-
);
149-
150-
if (result.status !== 0) {
151-
throw new Error(`${mode} wrapper failed with exit code ${result.status}`);
152-
}
153-
}
154-
155126
function bundleTo(entryFile: string, outputFile: string) {
156127
runPushy(
157128
[
@@ -171,6 +142,35 @@ function bundleTo(entryFile: string, outputFile: string) {
171142
);
172143
}
173144

145+
function verifyGeneratedFile(label: string, filePath: string) {
146+
if (!fs.existsSync(filePath)) {
147+
throw new Error(`${label} file not found after generation: ${filePath}`);
148+
}
149+
console.log(
150+
`Verified ${label}: ${filePath} (${fs.statSync(filePath).size} bytes)`,
151+
);
152+
}
153+
154+
function generatePpkDiff(origin: string, next: string, output: string) {
155+
runPushy(
156+
['hdiff', origin, next, '--output', output, '--no-interactive'],
157+
projectRoot,
158+
);
159+
verifyGeneratedFile('ppk diff', output);
160+
}
161+
162+
function generateAndroidPackageDiff(
163+
apkPath: string,
164+
next: string,
165+
output: string,
166+
) {
167+
runPushy(
168+
['hdiffFromApk', apkPath, next, '--output', output, '--no-interactive'],
169+
projectRoot,
170+
);
171+
verifyGeneratedFile('package diff', output);
172+
}
173+
174174
async function main() {
175175
prepareDir();
176176

@@ -186,11 +186,7 @@ async function main() {
186186
ensureHdiffModule();
187187

188188
console.log('Generating ppk diff...');
189-
runHdiffWrapper('ppk', v1, v2, ppkDiff);
190-
if (!fs.existsSync(ppkDiff)) {
191-
throw new Error(`ppk diff file not found after generation: ${ppkDiff}`);
192-
}
193-
console.log(`Verified ppk diff: ${ppkDiff} (${fs.statSync(ppkDiff).size} bytes)`);
189+
generatePpkDiff(v1, v2, ppkDiff);
194190

195191
if (platform === 'android') {
196192
const apkPath = path.join(
@@ -206,17 +202,15 @@ async function main() {
206202

207203
fs.copyFileSync(apkPath, path.join(artifactsDir, LOCAL_UPDATE_FILES.apk));
208204
console.log('Generating package diff...');
209-
runHdiffWrapper(
210-
'apk',
205+
const packageDiffPath = path.join(
206+
artifactsDir,
207+
LOCAL_UPDATE_FILES.packageDiff,
208+
);
209+
generateAndroidPackageDiff(
211210
apkPath,
212211
v3,
213-
path.join(artifactsDir, LOCAL_UPDATE_FILES.packageDiff),
212+
packageDiffPath,
214213
);
215-
const packageDiffPath = path.join(artifactsDir, LOCAL_UPDATE_FILES.packageDiff);
216-
if (!fs.existsSync(packageDiffPath)) {
217-
throw new Error(`Package diff file not found after generation: ${packageDiffPath}`);
218-
}
219-
console.log(`Verified package diff: ${packageDiffPath} (${fs.statSync(packageDiffPath).size} bytes)`);
220214
}
221215

222216
const manifestPath = path.join(artifactsDir, 'manifest.json');

‎Example/e2etest/scripts/run-hdiff-wrapper.js‎

Lines changed: 0 additions & 77 deletions
This file was deleted.

‎src/__tests__/client.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, mock, test } from 'bun:test';
1+
import { afterEach, describe, expect, mock, test } from 'bun:test';
22

33
const importFreshClient = (cacheKey: string) => import(`../client?${cacheKey}`);
44

@@ -366,6 +366,12 @@ describe('Pushy server config', () => {
366366
});
367367

368368
describe('downloadUpdate fallback chain', () => {
369+
const realSetTimeout = globalThis.setTimeout;
370+
371+
afterEach(() => {
372+
globalThis.setTimeout = realSetTimeout;
373+
});
374+
369375
const setupDownloadMocks = ({
370376
downloadPatchFromPpk = mock(() => Promise.resolve()),
371377
downloadPatchFromPackage = mock(() => Promise.resolve()),
@@ -382,7 +388,6 @@ describe('downloadUpdate fallback chain', () => {
382388
});
383389

384390
// Override setTimeout to skip real backoff delays in retry tests
385-
const realSetTimeout = globalThis.setTimeout.bind(globalThis);
386391
globalThis.setTimeout = ((fn: (...args: any[]) => void, _ms?: number) =>
387392
realSetTimeout(fn, 0)) as unknown as typeof setTimeout;
388393

0 commit comments

Comments
 (0)