Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 121 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ concurrency:
cancel-in-progress: true

jobs:
check:
lint:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: check
name: lint
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
Expand All @@ -34,7 +34,87 @@ jobs:
- uses: PerfectPan/gh-repo-checks@v1
with:
check: release-plan
- run: pnpm run check
- name: Format, docs and duplicates
run: pnpm run format:check && pnpm run check:docs && pnpm run duplicates
# Type-aware lint resolves built shell exports and the website's generated route tree, without needing a full site build.
- name: Prepare lint inputs
run: >-
pnpm --filter @rivus/agent-kit... --filter @rivus/agent-kit-collab... run build &&
pnpm --filter website exec tsr generate
- name: Lint
# Cache the workspace listing once so all 38 package `vp lint` processes skip spawning `pnpm ls`.
run: >-
AGENT_KIT_PNPM_LIST_ROOT="$(node -p 'fs.realpathSync(process.cwd())')"
AGENT_KIT_PNPM_LIST_JSON="$(pnpm ls -r --depth -1 --json)"
pnpm run lint

verify:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: verify
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: pnpm/setup@v3
with:
runtime: node
require-lockfile: true
cache: true
- name: Build
run: pnpm run build
- name: Knip, typecheck and package check
run: pnpm run knip && pnpm run knip:production && pnpm run typecheck && pnpm run check:package

test:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: test
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: pnpm/setup@v3
with:
runtime: node
require-lockfile: true
cache: true
# Only the published shells' built entries are imported by tests; website build stays in `verify`.
- name: Build shells
run: pnpm --filter @rivus/agent-kit... --filter @rivus/agent-kit-collab... run build
# Cap workspace concurrency to 2 because Vitest already parallelizes test files across all runner cores.
- name: Test packages
run: pnpm -r --no-sort --workspace-concurrency=2 --filter '!architecture-boundaries' run test

# Runs the boundary manifest tests and the 387-case `run-lint-cases.ts` suite on its own runner so its parallel
# `vp lint` processes do not contend with Vitest workers for the 4-core CPU.
architecture:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: architecture
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: pnpm/setup@v3
with:
runtime: node
require-lockfile: true
cache: true
- name: Architecture tests
run: pnpm --filter architecture-boundaries run test

# Aggregate status check preserving the `check` context name required by branch protection.
check:
if: always() && (github.event_name != 'pull_request' || !github.event.pull_request.draft)
name: check
needs: [lint, verify, test, architecture]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Verify required jobs succeeded
run: |
if [ "${{ needs.lint.result }}" != "success" ] || [ "${{ needs.verify.result }}" != "success" ] || [ "${{ needs.test.result }}" != "success" ] || [ "${{ needs.architecture.result }}" != "success" ]; then
echo "lint=${{ needs.lint.result }}, verify=${{ needs.verify.result }}, test=${{ needs.test.result }}, architecture=${{ needs.architecture.result }}"
exit 1
fi

# The tests of every workspace package on Windows, where `\` is a path separator and there are no POSIX signals,
# file modes or process identity. The aggregate gate stays on Linux.
Expand All @@ -58,6 +138,41 @@ jobs:
cache: true
# The shell's tests import its built entries, as in the aggregate gate, which builds before it tests.
- run: pnpm --filter @rivus/agent-kit... run build
- run: >-
pnpm -r --no-bail --no-sort
--filter '!@rivus/agent-kit-collab' test
# Exclude harness and architecture-boundaries, which run in dedicated parallel Windows jobs so heavy NTFS/icacls
# churn does not starve SQLite-based provider tests into 5s timeouts.
- name: Package tests
run: >-
pnpm -r --no-bail --no-sort --workspace-concurrency=2
--filter '!@rivus/agent-kit-collab'
--filter '!@rivus/agent-kit-harness'
--filter '!architecture-boundaries' test

windows-harness:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: windows-harness
runs-on: windows-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: pnpm/setup@v3
with:
runtime: node
require-lockfile: true
cache: true
- name: Harness tests
run: pnpm --filter @rivus/agent-kit-harness run test

windows-architecture:
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
name: windows-architecture
runs-on: windows-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v7
- uses: pnpm/setup@v3
with:
runtime: node
require-lockfile: true
cache: true
- name: Architecture tests
run: pnpm --filter architecture-boundaries run test
86 changes: 59 additions & 27 deletions infra/architecture/run-lint-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ import {
writeFileSync
} from "node:fs";
import { createRequire } from "node:module";
import { constants, tmpdir } from "node:os";
import { availableParallelism, constants, tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";

import { cases } from "./lint-cases.ts";
import type { Case } from "./case.ts";
import { workspaceProjects } from "./lint.ts";
import { pnpmListJson } from "./workspace.ts";

const ROOT = realpathSync(fileURLToPath(new URL("../..", import.meta.url)));
const run = promisify(execFile);
Expand Down Expand Up @@ -68,10 +69,15 @@ function lineOf(diagnostic: Diagnostic): string {
}

/** `vp lint` in one package of the copy, as `pnpm -r run lint` runs it there. */
async function lint(copy: string, folder: string, files: readonly string[]): Promise<Diagnostic[]> {
async function lint(
copy: string,
folder: string,
files: readonly string[],
env?: NodeJS.ProcessEnv
): Promise<Diagnostic[]> {
const cwd = join(copy, folder);
const args = ["lint", "--format", "json", ...files];
const options = { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024 } as const;
const options = { cwd, encoding: "utf8", maxBuffer: 64 * 1024 * 1024, ...(env ? { env } : {}) } as const;
// vp exits non-zero when it reports errors; the JSON on stdout is the result either way.
const { stdout } = await run(process.execPath, [vp, ...args], options).catch(
(error: { stdout?: string; stderr?: string }) => {
Expand Down Expand Up @@ -208,7 +214,7 @@ async function nestedProvider(copy: string): Promise<Diagnostic[]> {
}

/** The generated override must enable the Node boundary rule even when the top-level plugins list omits import. */
async function restrictedPlugins(copy: string): Promise<Diagnostic[]> {
async function restrictedPlugins(copy: string, env?: NodeJS.ProcessEnv): Promise<Diagnostic[]> {
const folder = "packages/sessions";
const config = join(copy, folder, "vite.config.ts");
const original = readFileSync(config, "utf8");
Expand All @@ -223,14 +229,14 @@ async function restrictedPlugins(copy: string): Promise<Diagnostic[]> {
writeFileSync(join(copy, folder, "src/plugin-node.ts"), 'export { readFile } from "node:fs/promises";\n');
writeFileSync(join(copy, folder, "src/plugin-plain.ts"), 'export { ok } from "@rivus/agent-kit-catalog/public";\n');
try {
return await lint(copy, folder, ["src/plugin-node.ts", "src/plugin-plain.ts"]);
return await lint(copy, folder, ["src/plugin-node.ts", "src/plugin-plain.ts"], env);
} finally {
writeFileSync(config, original);
}
}

/** A new provider fact must reach the context rule without updating infrastructure's marker list. */
async function addedProviderMarker(copy: string): Promise<Diagnostic[]> {
async function addedProviderMarker(copy: string, env?: NodeJS.ProcessEnv): Promise<Diagnostic[]> {
const facts = join(copy, "packages/providers/pi/src/facts.ts");
const original = readFileSync(facts, "utf8");
const marker = "PROVIDER_MARKER_PROBE";
Expand All @@ -244,7 +250,7 @@ async function addedProviderMarker(copy: string): Promise<Diagnostic[]> {
const file = join(copy, "packages/catalog/src/marker-probe.ts");
writeFileSync(file, `export const marker = "${marker}";\n`);
try {
return await lint(copy, "packages/catalog", ["src/marker-probe.ts"]);
return await lint(copy, "packages/catalog", ["src/marker-probe.ts"], env);
} finally {
writeFileSync(facts, original);
rmSync(file);
Expand Down Expand Up @@ -298,34 +304,60 @@ try {
}
spiProvider(copy);
spiProvider(copy, true);
for (const batch of batches()) {
const undo = batch.map((entry) => apply(copy, entry));
try {
const pkg = batch[0]?.pkg ?? "";
const diagnostics = await lint(
copy,
`packages/${pkg}`,
batch.map(({ path }) => path)
);
for (const entry of batch) {
const own = diagnostics.filter(({ filename }) => filename === entry.path);
failures += report(entry.name, `packages/${pkg}/${entry.path}`, entry.expected, own) ? 0 : 1;
}
} finally {
for (const restore of undo.toReversed()) {
restore();
// Capture the workspace listing once after synthetic providers exist so child `vp lint` processes skip `pnpm ls`.
// Each batch lints only a few files, so pin Rayon to 1 thread per process to avoid N×M CPU oversubscription.
const cachedListEnv: NodeJS.ProcessEnv = {
...process.env,
RAYON_NUM_THREADS: "1",
AGENT_KIT_PNPM_LIST_ROOT: copy,
AGENT_KIT_PNPM_LIST_JSON: pnpmListJson(copy)
};
// Different packages mutate disjoint folders, so run package groups concurrently (largest first to avoid a tail)
// while keeping batches within the same package sequential.
const groups = [...Map.groupBy(batches(), (batch) => batch[0]?.pkg ?? "").values()].toSorted(
(a, b) => b.length - a.length
);
let nextGroup = 0;
const concurrency = Math.max(2, Math.min(availableParallelism(), 4, groups.length));
await Promise.all(
Array.from({ length: concurrency }, async () => {
while (nextGroup < groups.length) {
const group = groups[nextGroup++];
if (group === undefined) {
return;
}
for (const batch of group) {
const undo = batch.map((entry) => apply(copy, entry));
try {
const pkg = batch[0]?.pkg ?? "";
const diagnostics = await lint(
copy,
`packages/${pkg}`,
batch.map(({ path }) => path),
cachedListEnv
);
for (const entry of batch) {
const own = diagnostics.filter(({ filename }) => filename === entry.path);
failures += report(entry.name, `packages/${pkg}/${entry.path}`, entry.expected, own) ? 0 : 1;
}
} finally {
for (const restore of undo.toReversed()) {
restore();
}
}
}
}
}
}
})
);
failures += report(
"agent marker: added provider fact",
"packages/catalog/src/marker-probe.ts",
["agent-marker"],
await addedProviderMarker(copy)
await addedProviderMarker(copy, cachedListEnv)
)
? 0
: 1;
const restricted = await restrictedPlugins(copy);
const restricted = await restrictedPlugins(copy, cachedListEnv);
failures += report(
"typescript-only top-level plugins: Node builtin",
"packages/sessions/src/plugin-node.ts",
Expand Down
5 changes: 5 additions & 0 deletions infra/architecture/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { execFileSync } from "node:child_process";

/** Lists the workspace members as raw JSON from `pnpm ls -r --depth -1 --json`. */
export function pnpmListJson(root: string): string {
// run-lint-cases spawns `vp lint` dozens of times against an unchanged fixture copy; reuse one listing when rooted
// at the same directory instead of invoking pnpm on every process startup.
if (process.env.AGENT_KIT_PNPM_LIST_ROOT === root && process.env.AGENT_KIT_PNPM_LIST_JSON !== undefined) {
return process.env.AGENT_KIT_PNPM_LIST_JSON;
}
return execFileSync("pnpm", ["ls", "-r", "--depth", "-1", "--json"], {
cwd: root,
encoding: "utf8",
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"check:package": "pnpm -r run check:package",
"duplicates": "jscpd --config node_modules/@perfectpan/lint-config/jscpd.json packages apps infra scripts tests --ignore '**/node_modules/**,**/dist/**,**/coverage/**,**/.vite/**,**/.source/**,**/.tanstack/**,**/routeTree.gen.ts,**/*.json,**/*.test.ts,**/*.test.tsx,**/test/support/**,**/test/fixtures/**' --format 'typescript,tsx'",
"duplicates:audit": "jscpd --config node_modules/@perfectpan/lint-config/jscpd-audit.json packages apps infra scripts tests --absolute --output tmp/duplicates-audit --ignore '**/node_modules/**,**/dist/**,**/coverage/**,**/.vite/**,**/.source/**,**/.tanstack/**,**/routeTree.gen.ts,**/*.json' --format 'typescript,tsx'",
"format": "pnpm -r run format",
"format:check": "pnpm -r run format:check",
"format": "pnpm -r --no-sort run format",
"format:check": "pnpm -r --no-sort run format:check",
"knip": "knip",
"knip:production": "knip --production",
"lint": "pnpm -r run lint",
"lint": "pnpm -r --no-sort run lint",
"size:update": "node scripts/update-size-budgets.ts",
"test": "pnpm -r run test",
"typecheck": "pnpm -r run typecheck",
"test": "pnpm -r --no-sort run test",
"typecheck": "pnpm -r --no-sort run typecheck",
"version-packages": "changeset version"
},
"engines": {
Expand Down
Loading