Skip to content

Commit d66afed

Browse files
committed
A bunch of test fixes for linux and macOS. Also added linux testing to the persistent tests. Switched the linux tests over to tart instead of docker.
1 parent 6074eb3 commit d66afed

29 files changed

Lines changed: 137 additions & 108 deletions

.cirrus.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ integration_test_dev_macos_task:
2424
- npm run test:integration -- --disable-console-intercept $DEBUG --no-file-parallelism
2525

2626
integration_test_dev_linux_task:
27-
arm_container:
28-
image: kevinwang5658/codify-test-linux:latest
27+
# trick cirrus CI to use tart here to run a linux instance
28+
macos_instance:
29+
image: codify-test-vm-linux
2930
# node_modules_cache:
3031
# folder: node_modules
3132
# fingerprint_script: cat package-lock.json
3233
# populate_script: npm ci
3334
test_script:
34-
- adduser --disabled-password --gecos '' newuser
35-
- su - newuser
35+
# - adduser --disabled-password --gecos '' newuser
36+
# - su - newuser
3637
- npm ci
3738
- npm run test:integration -- --disable-console-intercept $DEBUG --no-file-parallelism
3839

.run/test_integration_dev.run.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
</scripts>
88
<node-interpreter value="project" />
99
<envs />
10+
<EXTENSION ID="com.intellij.javascript.debugger.execution.StartBrowserRunConfigurationExtension">
11+
<browser with-js-debugger="true" />
12+
</EXTENSION>
1013
<method v="2" />
1114
</configuration>
1215
</component>

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"@types/node": "^18",
5656
"@types/plist": "^3.0.5",
5757
"@types/semver": "^7.5.4",
58-
"codify-plugin-test": "0.0.53-beta15",
58+
"codify-plugin-test": "0.0.53-beta17",
5959
"commander": "^12.1.0",
6060
"eslint": "^8.51.0",
6161
"eslint-config-oclif": "^5",

scripts/run-tests.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Shell, SpawnStatus, VerbosityLevel } from 'codify-plugin-lib';
2-
import { testSpawn } from 'codify-plugin-test';
2+
import { testSpawn, TestUtils } from 'codify-plugin-test';
33
import { Command } from 'commander';
44
import { spawn } from 'node:child_process';
55
import * as inspector from 'node:inspector';
@@ -27,7 +27,7 @@ async function main(argument: string, args: { operatingSystem: string; persisten
2727
}
2828

2929
if (args.launchPersistent) {
30-
await launchPersistentVm();
30+
await launchPersistentVm(args.operatingSystem);
3131
return process.exit(0);
3232
}
3333

@@ -69,7 +69,9 @@ async function launchSingleTest(test: string, debug: boolean, operatingSystem: s
6969
}
7070

7171
async function launchPersistentTest(test: string, debug: boolean, operatingSystem: string) {
72-
if (operatingSystem === 'darwin') {
72+
const shell = operatingSystem === 'darwin' ? 'zsh' : 'bash';
73+
74+
// if (operatingSystem === 'darwin') {
7375
const { data: vmList } = await codifySpawn('tart list --format json');
7476
console.log(vmList);
7577

@@ -80,7 +82,8 @@ async function launchPersistentTest(test: string, debug: boolean, operatingSyste
8082
}
8183

8284
const vmName = runningVm.Name;
83-
const dir = '/Users/admin/codify-homebrew-plugin';
85+
const dir = '~/codify-homebrew-plugin';
86+
// const dir = '/Volumes/My\\ Shared\\ Files/plugin'
8487

8588
const debugFlag = debug ? ' -e DEBUG="--inspect-brk=9229"' : ''
8689

@@ -93,15 +96,18 @@ async function launchPersistentTest(test: string, debug: boolean, operatingSyste
9396

9497
console.log('Done refreshing files on VM. Starting tests...');
9598
VerbosityLevel.set(3);
96-
await codifySpawn(`tart exec -i ${vmName} zsh -i -c "cd ${dir} && FORCE_COLOR=true npm run test -- ${test} --disable-console-intercept ${debugFlag} --no-file-parallelism"`);
97-
}
99+
await codifySpawn(`tart exec ${vmName} ${shell} -c "cd ${dir} && FORCE_COLOR=true npm run test -- ${test} --disable-console-intercept ${debugFlag} --no-file-parallelism"`, { throws: false });
100+
// }
98101
}
99102

100-
async function launchPersistentVm() {
103+
async function launchPersistentVm(operatingSystem: string) {
101104
const newVmName = `codify-test-vm-${Date.now()}`;
105+
const shell = operatingSystem === 'darwin' ? 'zsh' : 'bash';
106+
102107
console.log(`Cloning new VM... ${newVmName}`);
103108

104-
await testSpawn(`tart clone codify-test-vm ${newVmName}`);
109+
const image = (operatingSystem === 'darwin') ? 'codify-test-vm' : 'codify-test-vm-linux';
110+
await testSpawn(`tart clone ${image} ${newVmName}`);
105111
testSpawn(`tart run ${newVmName}`)
106112
.then(cleanupVm)
107113

@@ -115,7 +121,7 @@ async function launchPersistentVm() {
115121

116122
const { data: ipAddr } = await testSpawn(`tart ip ${newVmName}`);
117123
await testSpawn(`sshpass -p "admin" rsync -avz -e 'ssh -o PubkeyAuthentication=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' --exclude 'node_modules' --exclude '.git' --exclude 'dist' --exclude '.fleet' ${process.cwd()} admin@${ipAddr}:~`);
118-
await testSpawn(`tart exec ${newVmName} zsh -i -c "cd ~/codify-homebrew-plugin && npm ci"`);
124+
await testSpawn(`tart exec ${newVmName} ${shell} -i -c "cd ~/codify-homebrew-plugin && npm ci"`);
119125
console.log('Finished installing dependencies. Start tests in a new terminal window.');
120126

121127
await sleep(1_000_000_000);

src/resources/asdf/asdf-install.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,22 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
141141

142142
// Uninstall plugin versions listed in .tool-versions
143143
for (const { plugin, version } of desiredTools) {
144-
await $.spawn(`asdf uninstall ${plugin} ${version}`, { interactive: true });
144+
await $.spawn(`asdf uninstall ${plugin} ${version === 'latest'? `$(asdf latest ${plugin})` : version}`, { interactive: true });
145145
}
146146

147147
return;
148148
}
149149

150150
// Other path is uninstalled through the stateful parameter
151-
await $.spawn(`asdf uninstall ${plan.currentConfig?.plugin} ${plan.currentConfig.versions?.join(' ')}`, { interactive: true });
151+
await $.spawn(`asdf uninstall ${plan.currentConfig?.plugin} ${plan.currentConfig.versions
152+
?.map(version => version === 'latest'? `$(asdf latest ${plan.currentConfig?.plugin})` : version)
153+
.join(' ')}`, { interactive: true });
152154
}
153155

154156
private async getToolVersions(directory: string): Promise<Array<{ plugin: string; version: string }>> {
155157
const toolsVersions = (await fs.readFile(path.join(directory, '.tool-versions'))).toString();
156158

157-
return toolsVersions.split(/\n/)
159+
return toolsVersions.split(/\n/g)
158160
.filter(Boolean)
159161
.map((l) => {
160162
const matches = l.match(TOOL_VERSIONS_REGEX);
@@ -164,6 +166,6 @@ export class AsdfInstallResource extends Resource<AsdfInstallConfig> {
164166

165167
return matches.slice(1, 3)
166168
})
167-
.map(([plugin, version, file]) => ({ plugin, version, file }));
169+
.map(([plugin, version]) => ({ plugin, version }));
168170
}
169171
}

src/resources/asdf/asdf.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export class AsdfResource extends Resource<AsdfConfig> {
4646
}
4747

4848
await $.spawn('brew install asdf', { interactive: true, env: { HOMEBREW_NO_AUTO_UPDATE: 1 } });
49-
5049
}
5150

5251
if (Utils.isLinux()) {
@@ -65,20 +64,12 @@ export class AsdfResource extends Resource<AsdfConfig> {
6564
await fs.chmod(path.join(asdfDir, 'asdf'), 0o755);
6665

6766
await fs.rm(tmpDir, { recursive: true, force: true });
67+
68+
await FileUtils.addPathToShellRc(path.join(os.homedir(), '.local', 'bin'), true);
6869
}
6970

70-
await FileUtils.addPathToShellRc(path.join(os.homedir(), '.local', 'bin'), true);
7171
// eslint-disable-next-line no-template-curly-in-string
7272
await FileUtils.addToShellRc('export PATH="${ASDF_DATA_DIR:-$HOME/.asdf}/shims:$PATH"')
73-
74-
// TODO: Move OsUtils to a separate name space? All things that have to do with the os.
75-
// TODO: Add a way to run multiple commands in sequence
76-
// TODO: Change all plugins to install to ~/.local/bin
77-
78-
await $.spawnSafe('which asdf', { interactive: true });
79-
await $.spawnSafe('ls ~/.local/bin');
80-
console.log((await $.spawnSafe('echo $PATH', { interactive: true })).data);
81-
8273
}
8374

8475
async destroy(): Promise<void> {

src/resources/docker/docker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class DockerResource extends Resource<DockerConfig> {
9393

9494
async destroy(plan: DestroyPlan<DockerConfig>): Promise<void> {
9595
const $ = getPty();
96-
await $.spawnSafe('/Applications/Docker.app/Contents/MacOS/uninstall')
96+
await $.spawnSafe('/Applications/Docker.app/Contents/MacOS/uninstall', { interactive: true, requiresRoot: true })
9797
await fs.rm(path.join(os.homedir(), 'Library/Group\\ Containers/group.com.docker'), { recursive: true, force: true });
9898
await fs.rm(path.join(os.homedir(), 'Library/Containers/com.docker.docker/Data'), { recursive: true, force: true });
9999
await fs.rm(path.join(os.homedir(), '.docker'), { recursive: true, force: true });

src/resources/xcode-tools/xcode-tools.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class XcodeToolsResource extends Resource<XCodeToolsConfig> {
4545
const { data } = await $.spawn('softwareupdate -l', { interactive: true });
4646

4747
// This regex will only match the label because it doesn't match commas.
48-
const labelRegex = /(Command Line Tools[^,]*\d+\.\d+)/g
48+
const labelRegex = /(Command Line Tools[^,]*\d+\.\d+?)(?=\s+)/g
4949
const xcodeToolsVersion = data.match(labelRegex);
5050

5151
if (!xcodeToolsVersion || xcodeToolsVersion.length === 0 || !xcodeToolsVersion[0]) {
@@ -67,6 +67,8 @@ export class XcodeToolsResource extends Resource<XCodeToolsConfig> {
6767
return compare(coerce(currentVer)!, coerce(prevVer)!) > 0 ? current : prev;
6868
}) : xcodeToolsVersion.at(0)!;
6969

70+
console.log('Latest version', latestVersion);
71+
7072
await $.spawn(`softwareupdate -i "${latestVersion}" --verbose`, { requiresRoot: true, interactive: true });
7173

7274
} finally {

test/apt/apt.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
22
import { PluginTester, testSpawn } from 'codify-plugin-test';
33
import * as path from 'node:path';
44
import { TestUtils } from '../test-utils.js';
5-
import { SpawnStatus } from 'codify-plugin-lib';
5+
import { SpawnStatus, Utils } from 'codify-plugin-lib';
66

7-
describe('Apt resource integration tests', () => {
7+
describe('Apt resource integration tests', { skip: !Utils.isLinux() }, () => {
88
const pluginPath = path.resolve('./src/index.ts');
99

1010
it('Can install and uninstall apt packages', { timeout: 300000 }, async () => {

0 commit comments

Comments
 (0)