Skip to content

Commit 0b43e20

Browse files
Kevin/automated testing (#28)
Added automated tests on github actions: Shard macOS and linux tests to improve speed Fix testing problems Fix platform problems (had to integrate the existing tests with the differences between tart and the github actions runner) Fixed structural problems Added claude to run on test failure to attempt to auto fixing
1 parent e504ff8 commit 0b43e20

34 files changed

Lines changed: 316 additions & 230 deletions

.circleci/config.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: 2.1
2+
3+
jobs:
4+
test:
5+
parameters:
6+
executor:
7+
type: executor
8+
executor: << parameters.executor >>
9+
steps:
10+
- checkout
11+
- node/install:
12+
node-version: '24'
13+
- run:
14+
name: Enable linger for current user (Linux only)
15+
command: |
16+
if [[ "$OSTYPE" == "linux"* ]]; then
17+
loginctl enable-linger $(whoami)
18+
sudo chown -R circleci:circleci /usr/local /opt /var/tmp
19+
fi
20+
- run:
21+
name: Install dependencies
22+
command: npm ci
23+
- run:
24+
name: Clean up pre-installed tools
25+
command: npx tsx scripts/cleanup-circleci.ts
26+
no_output_timeout: 10m
27+
- run:
28+
name: Run tests
29+
command: npm run test -- ./test --no-file-parallelism --disable-console-intercept
30+
no_output_timeout: 30m
31+
32+
orbs:
33+
node: circleci/node@6
34+
35+
executors:
36+
linux-x86:
37+
machine:
38+
image: ubuntu-2404:current
39+
resource_class: medium
40+
linux-arm:
41+
machine:
42+
image: ubuntu-2404:current
43+
resource_class: arm.medium
44+
macos:
45+
macos:
46+
xcode: '26.4.0'
47+
resource_class: m4pro.medium
48+
49+
#workflows:
50+
# test-all:
51+
# jobs:
52+
# - test:
53+
# matrix:
54+
# parameters:
55+
# executor: [linux-arm]

.github/workflows/claude-fixer.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Claude Test Fixer
2+
on:
3+
workflow_run:
4+
workflows: ["Test all cron (Linux)", "Test all cron (MacOS)"]
5+
types: [completed]
6+
7+
jobs:
8+
fix-on-failure:
9+
runs-on: ubuntu-latest
10+
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
actions: read # Allows Claude to read the logs of the failed run
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Claude Fix Failed Tests
18+
uses: anthropics/claude-code-action@v1
19+
with:
20+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
21+
prompt: |
22+
The "CI Tests" workflow just failed.
23+
1. Analyze the logs from the last failed run.
24+
2. Identify the root cause of the test failure.
25+
3. Implement a fix and create a new pull request.
26+
27+
28+
29+
additional_permissions: |
30+
actions: read
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Test all cron (Linux)
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- release
10+
schedule:
11+
- cron: '0 0 * * *' # Every day at midnight UTC
12+
workflow_dispatch:
13+
14+
jobs:
15+
build-and-test:
16+
runs-on: ${{ matrix.os }}
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest]
22+
# os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
23+
shard: ["1/20", "2/20", "3/20", "4/20", "5/20", "6/20", "7/20", "8/20", "9/20", "10/20", "11/20", "12/20", "13/20", "14/20", "15/20", "16/20", "17/20", "18/20", "19/20", "20/20"]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Use Node.js 24
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '24.x'
31+
cache: 'npm'
32+
- name: Enable linger for admin user (Linux only)
33+
if: runner.os == 'Linux'
34+
run: loginctl enable-linger $(whoami)
35+
36+
- run: npm ci
37+
- run: npx tsx scripts/cleanup-github-actions.ts
38+
39+
# - name: Setup tmate session
40+
# uses: mxschmitt/action-tmate@v3
41+
42+
- name: Run tests (Linux)
43+
if: runner.os == 'Linux'
44+
run: npm run test -- ./test --no-file-parallelism --disable-console-intercept --shard ${{ matrix.shard }}
45+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Test all cron (MacOS)
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- release
10+
schedule:
11+
- cron: '0 0 * * *' # Every day at midnight UTC
12+
workflow_dispatch:
13+
14+
jobs:
15+
build-and-test:
16+
runs-on: ${{ matrix.os }}
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [macos-latest]
22+
# os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
23+
shard: ["1/5", "2/5", "3/5", "4/5", "5/5"]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Use Node.js 24
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: '24.x'
31+
cache: 'npm'
32+
33+
- run: npm ci
34+
- run: npx tsx scripts/cleanup-github-actions.ts
35+
36+
# - name: Setup tmate session
37+
# uses: mxschmitt/action-tmate@v3
38+
39+
- name: Run tests (macOS - zsh login shell)
40+
if: runner.os == 'macOS'
41+
shell: zsh {0}
42+
run: |
43+
sudo chsh -s $(which zsh) $USER
44+
echo $0
45+
46+
echo $ZSH_NAME $ZSH_VERSION
47+
export SHELL=/bin/zsh
48+
touch ~/.zshrc
49+
unset JAVA_HOME
50+
export PATH=/Users/runner/.local/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/opt/curl/bin:/usr/local/bin:/usr/local/sbin:/Users/runner/bin:/usr/bin:/bin:/usr/sbin:/sbin
51+
export CI=true
52+
53+
npm run test -- ./test --no-file-parallelism --disable-console-intercept --exclude ./test/homebrew --shard ${{ matrix.shard }}
54+

.github/workflows/run-all-unit-tests.yaml

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

.run/test_integration_dev -- $FilePathRelativeToProjectRoot$.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="test:integration:dev -- $FilePathRelativeToProjectRoot$" type="js.build_tools.npm" nameIsGenerated="true">
2+
<configuration default="false" name="test:integration:dev -- $FilePathRelativeToProjectRoot$" type="js.build_tools.npm">
33
<package-json value="$PROJECT_DIR$/package.json" />
44
<command value="run" />
55
<scripts>

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"license": "ISC",
4343
"type": "module",
4444
"dependencies": {
45-
"@codifycli/plugin-core": "1.1.0-beta6",
45+
"@codifycli/plugin-core": "1.1.0-beta10",
4646
"@codifycli/schemas": "1.0.0",
4747
"ajv": "^8.18.0",
4848
"ajv-formats": "^2.1.1",
@@ -58,7 +58,7 @@
5858
"devDependencies": {
5959
"@anthropic-ai/claude-agent-sdk": "^0.2.97",
6060
"@apidevtools/json-schema-ref-parser": "^11.7.2",
61-
"@codifycli/plugin-test": "^1.0.0",
61+
"@codifycli/plugin-test": "1.1.0-beta3",
6262
"@fastify/merge-json-schemas": "^0.2.0",
6363
"@oclif/prettier-config": "^0.2.1",
6464
"@oclif/test": "^3",

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { JSONSchema } from '@apidevtools/json-schema-ref-parser';
22
import { createRequire } from 'node:module';
33
import { Ajv } from 'ajv';
44
import { VerbosityLevel } from '@codifycli/plugin-core';
5-
import { SequentialPty } from '@codifycli/plugin-core/dist/pty/seqeuntial-pty';
5+
import { SequentialPty } from '@codifycli/plugin-core';
66
import { IpcMessage, IpcMessageSchema, MessageStatus, ResourceSchema } from '@codifycli/schemas';
77
import mergeJsonSchemas from 'merge-json-schemas';
88
import { ChildProcess, fork } from 'node:child_process';

scripts/cleanup-github-actions.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { PluginTester, testSpawn } from '@codifycli/plugin-test';
2+
import path from 'node:path';
3+
import { Utils } from '@codifycli/plugin-core';
4+
5+
const pluginPath = path.resolve('./src/index.ts');
6+
7+
8+
if (Utils.isLinux()) {
9+
// Uninstall resources that have Codify resource definitions
10+
await PluginTester.uninstall(pluginPath, [
11+
{ type: 'docker' },
12+
{ type: 'aws-cli'}
13+
]);
14+
15+
await testSpawn('apt-get autoremove -y ruby rpm python awscli needrestart', { requiresRoot: true }); // remove needrestart to keep logs clean.
16+
17+
await testSpawn('rustup self uninstall -y');
18+
19+
await testSpawn('rm -rf /usr/bin/go', { requiresRoot: true })
20+
await testSpawn('rm -rf /usr/bin/python', { requiresRoot: true })
21+
await testSpawn('rm -rf /usr/bin/ruby', { requiresRoot: true })
22+
23+
// await testSpawn('apt install --reinstall command-not-found', { requiresRoot: true });
24+
25+
// MacOS
26+
} else {
27+
await PluginTester.uninstall(pluginPath, [
28+
{ type: 'aws-cli' },
29+
]);
30+
31+
await testSpawn('brew uninstall ant gradle kotlin maven selenium-server google-chrome pipx $(brew list | grep -E \'^python(@|$)\') $(brew list | grep -E \'^ruby(@|$)\') aws-sam-cli azure-cli rustup git-lfs $(brew list | grep -E \'^openjdk(@|$)\')', { interactive: true });
32+
33+
}

0 commit comments

Comments
 (0)