Skip to content

Commit eae2632

Browse files
author
s39-dev
committed
test(tui): pin the update-service host to a published release target
McodeUpdateService.check() calls resolveMcodeReleaseTarget() with no override, so it reads process.platform and process.arch. release.ts publishes only darwin-arm64, darwin-x64, linux-x64, windows-x64 and windows-arm64, and a host outside that set — linux-arm64, for example — fails every check with "Unsupported MCode update host" regardless of what the test asserts. Pin both properties with Object.defineProperty in beforeEach and restore the captured host descriptors in afterEach, so the rest of the process is untouched. The fallback is linux-x64, a real REQUIRED_V1_TARGETS entry, so the tests keep exercising a shipped target instead of an invented one. Hosts that already publish keep their own platform and arch, which leaves the win32-only install test on Windows driving the real win32 branch of resolveMcodeInstallRoot and detectMcodeInstallSource. Purely test infrastructure; release.ts TARGETS is unchanged, so whether linux-arm64 should become a published target stays a product decision.
1 parent cce4d9e commit eae2632

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

‎packages/tui/test/unit/update-service.test.ts‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync
44
import { createServer } from 'node:http';
55
import { tmpdir } from 'node:os';
66
import path from 'node:path';
7-
import { afterEach, describe, expect, it, vi } from 'vitest';
7+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
88
import { McodeUpdateService, type McodeUpdateDependencies } from '../../src/update/service.js';
99
import { resolveMcodeNpmDistribution } from '../../src/update/install-source.js';
10-
import type { McodeReleaseManifestV1 } from '../../src/update/release.js';
10+
import { resolveMcodeReleaseTarget, type McodeReleaseManifestV1 } from '../../src/update/release.js';
1111

1212
const temporaryRoots: string[] = [];
1313

@@ -56,6 +56,43 @@ afterEach(() => {
5656
}
5757
});
5858

59+
// McodeUpdateService.check() resolves the release target from the running
60+
// process, so this file only runs on a host release.ts actually publishes for.
61+
// A host outside that set (linux-arm64, for example) fails every check with
62+
// "Unsupported MCode update host" no matter what the test asserts. Pin the
63+
// reported platform and arch to a real required target for the duration of
64+
// each test, and restore the host descriptors afterwards so the rest of the
65+
// process is unaffected. Hosts that already publish keep their own values,
66+
// which leaves the win32-only install test exercising the real win32 branch.
67+
const hostIsRequiredTarget = (() => {
68+
try {
69+
resolveMcodeReleaseTarget();
70+
return true;
71+
} catch {
72+
return false;
73+
}
74+
})();
75+
const pinnedTarget = hostIsRequiredTarget
76+
? { platform: process.platform, arch: process.arch }
77+
: { platform: 'linux', arch: 'x64' };
78+
const hostDescriptors = {
79+
platform: Object.getOwnPropertyDescriptor(process, 'platform'),
80+
arch: Object.getOwnPropertyDescriptor(process, 'arch'),
81+
};
82+
83+
beforeEach(() => {
84+
for (const [key, value] of Object.entries(pinnedTarget)) {
85+
Object.defineProperty(process, key, { value, configurable: true });
86+
}
87+
});
88+
89+
afterEach(() => {
90+
for (const [key, descriptor] of Object.entries(hostDescriptors)) {
91+
if (!descriptor) continue;
92+
Object.defineProperty(process, key, descriptor);
93+
}
94+
});
95+
5996
describe('McodeUpdateService', () => {
6097
it
6198
.skipIf(process.platform !== 'win32')

0 commit comments

Comments
 (0)