diff hg-web/e2e/app_e2e_test.js @ 249:c5129452493e

[deploy] Bundle Mercurial with hg-web Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 04:16:45 -0700
parents 70de0c80d093
children
line wrap: on
line diff
--- a/hg-web/e2e/app_e2e_test.js	Tue Aug 04 02:44:06 2026 -0700
+++ b/hg-web/e2e/app_e2e_test.js	Tue Aug 04 04:16:45 2026 -0700
@@ -8,6 +8,7 @@
 const BASE_URL = 'http://127.0.0.1:6970';
 const RUNFILES = process.env.JS_BINARY__RUNFILES;
 const WORKSPACE = process.env.JS_BINARY__WORKSPACE;
+let hgCommand = 'hg';
 
 function run(command, args, options = {}) {
   const result = spawnSync(command, args, {
@@ -64,7 +65,7 @@
 
 function createFixtureRepository(root) {
   const options = { env: mercurialEnvironment(root) };
-  run('hg', ['init', root], options);
+  run(hgCommand, ['init', root], options);
   fs.mkdirSync(path.join(root, 'docs'), { recursive: true });
   fs.mkdirSync(path.join(root, 'src'), { recursive: true });
   fs.writeFileSync(
@@ -88,18 +89,18 @@
   fs.writeFileSync(path.join(root, 'sound.mp3'), Buffer.from('ID3'));
   fs.writeFileSync(path.join(root, 'document.pdf'), Buffer.from('%PDF-1.4\n%%EOF\n'));
   fs.writeFileSync(path.join(root, 'archive.bin'), Buffer.from([0, 1, 2, 3]));
-  run('hg', ['--repository', root, 'add'], options);
-  run('hg', ['--repository', root, 'commit', '-u', 'Test User <[email protected]>', '-m', 'Initial fixture'], options);
-  const firstNode = run('hg', ['--repository', root, 'log', '-r', '.', '-T', '{node}'], options);
+  run(hgCommand, ['--repository', root, 'add'], options);
+  run(hgCommand, ['--repository', root, 'commit', '-u', 'Test User <[email protected]>', '-m', 'Initial fixture'], options);
+  const firstNode = run(hgCommand, ['--repository', root, 'log', '-r', '.', '-T', '{node}'], options);
 
   fs.writeFileSync(
     path.join(root, 'README.md'),
     '# Updated Fixture Repository\n\n<script>window.__hgWebXss = true</script>\n\nSecond revision.\n',
   );
   fs.writeFileSync(path.join(root, 'new-file.txt'), 'new file\n');
-  run('hg', ['add', 'new-file.txt'], { ...options, cwd: root });
-  run('hg', ['--repository', root, 'commit', '-u', 'Test User <[email protected]>', '-m', 'Update fixture'], options);
-  const tipNode = run('hg', ['--repository', root, 'log', '-r', '.', '-T', '{node}'], options);
+  run(hgCommand, ['add', 'new-file.txt'], { ...options, cwd: root });
+  run(hgCommand, ['--repository', root, 'commit', '-u', 'Test User <[email protected]>', '-m', 'Update fixture'], options);
+  const tipNode = run(hgCommand, ['--repository', root, 'log', '-r', '.', '-T', '{node}'], options);
   return { firstNode, tipNode };
 }
 
@@ -147,16 +148,25 @@
   let browser;
 
   try {
-    const { firstNode, tipNode } = createFixtureRepository(fixtureRoot);
     const runfilesWorkspace = path.join(RUNFILES, WORKSPACE);
     const serverBinary = path.join(runfilesWorkspace, 'hg-web', 'hg_web_server');
+    hgCommand = path.join(
+      runfilesWorkspace,
+      'third_party',
+      'mercurial',
+      'runtime',
+      'bin',
+      'hg',
+    );
     const chromiumPath = path.resolve(process.env.CHROMIUM_PATH);
 
     assert.ok(fs.existsSync(serverBinary), `missing server binary: ${serverBinary}`);
+    assert.ok(fs.existsSync(hgCommand), `missing bundled Mercurial: ${hgCommand}`);
     assert.ok(fs.existsSync(chromiumPath), `missing Chromium binary: ${chromiumPath}`);
+    const { firstNode, tipNode } = createFixtureRepository(fixtureRoot);
 
     hgServer = spawn(
-      'hg',
+      hgCommand,
       [
         '--repository', fixtureRoot,
         'serve',
@@ -260,7 +270,7 @@
     assert.equal((await fetch(`${BASE_URL}/missing-route`)).status, 404);
 
     const identify = run(
-      'hg',
+      hgCommand,
       ['identify', `${BASE_URL}/repo`],
       { env: mercurialEnvironment(fixtureRoot) },
     );