env-secrets 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.claude/rules/cicd.md +189 -0
  2. package/.claude/rules/docs.md +96 -0
  3. package/.claude/rules/git-hooks.md +43 -0
  4. package/.claude/rules/local-dev-badges.md +91 -0
  5. package/.claude/rules/local-dev-env.md +382 -0
  6. package/.claude/rules/local-dev-license.md +104 -0
  7. package/.claude/rules/local-dev-mcp.md +70 -0
  8. package/.claude/rules/observability.md +23 -0
  9. package/.claude/rules/publishing-api.md +158 -0
  10. package/.claude/rules/publishing-apps.md +204 -0
  11. package/.claude/rules/publishing-apt.md +146 -0
  12. package/.claude/rules/publishing-brew.md +110 -0
  13. package/.claude/rules/publishing-cli.md +238 -0
  14. package/.claude/rules/publishing-libraries.md +115 -0
  15. package/.claude/rules/publishing-sdks.md +109 -0
  16. package/.claude/rules/publishing-web.md +185 -0
  17. package/.claude/rules/typescript-linting.md +141 -0
  18. package/.claude/rules/typescript-logging.md +356 -0
  19. package/.claude/rules/typescript-testing.md +185 -0
  20. package/.claude/settings.json +18 -0
  21. package/.claude/skills/github-health-check.skill +0 -0
  22. package/.codex/rules/cicd.md +21 -0
  23. package/.codex/rules/docs.md +98 -0
  24. package/.codex/rules/git-hooks.md +43 -0
  25. package/.codex/rules/github-health-check.md +440 -0
  26. package/.codex/rules/local-dev-env.md +47 -0
  27. package/.codex/rules/local-dev-license.md +3 -1
  28. package/.codex/rules/publishing-api.md +160 -0
  29. package/.codex/rules/publishing-apps.md +206 -0
  30. package/.codex/rules/publishing-apt.md +148 -0
  31. package/.codex/rules/publishing-brew.md +112 -0
  32. package/.codex/rules/publishing-cli.md +240 -0
  33. package/.codex/rules/publishing-libraries.md +117 -0
  34. package/.codex/rules/publishing-sdks.md +111 -0
  35. package/.codex/rules/publishing-web.md +187 -0
  36. package/.codex/rules/typescript-linting.md +143 -0
  37. package/.codex/rules/typescript-logging.md +358 -0
  38. package/.codex/rules/typescript-testing.md +187 -0
  39. package/.github/workflows/deploy-docs.yml +2 -2
  40. package/.github/workflows/unittests.yaml +1 -1
  41. package/.rulesrc.json +20 -0
  42. package/AGENTS.md +34 -0
  43. package/CLAUDE.md +58 -0
  44. package/README.md +17 -3
  45. package/__e2e__/aws-exec-args.test.ts +97 -1
  46. package/__e2e__/aws-secret-value-args.test.ts +142 -0
  47. package/__e2e__/utils/test-utils.ts +78 -0
  48. package/__tests__/cli/helpers.test.ts +35 -0
  49. package/__tests__/index.test.ts +208 -58
  50. package/dist/cli/helpers.js +13 -1
  51. package/dist/index.js +94 -44
  52. package/docker-compose.yaml +1 -1
  53. package/docs/AWS.md +42 -13
  54. package/package.json +6 -6
  55. package/src/cli/helpers.ts +16 -0
  56. package/src/index.ts +117 -52
@@ -0,0 +1,143 @@
1
+ # TypeScript Linting Rules
2
+
3
+ These rules are intended for Codex (CLI and app).
4
+
5
+ These rules provide TypeScript linting setup instructions following Everyday DevOps best practices from https://www.markcallen.com/typescript-linting/
6
+
7
+ ---
8
+
9
+ You are a TypeScript linting specialist. Your role is to implement comprehensive linting and code formatting for TypeScript/JavaScript projects following the Everyday DevOps best practices from https://www.markcallen.com/typescript-linting/
10
+
11
+ ## Your Responsibilities
12
+
13
+ 1. **Install Required Dependencies**
14
+
15
+ - Add eslint, prettier, and related packages
16
+ - Install typescript-eslint for TypeScript support
17
+ - Add eslint-plugin-prettier and eslint-config-prettier for Prettier integration
18
+ - Install globals package for environment definitions
19
+
20
+ 2. **Configure ESLint**
21
+
22
+ - Create eslint.config.js (for CommonJS) or eslint.config.mjs (for ES modules)
23
+ - Use the flat config format (not the legacy .eslintrc)
24
+ - Configure for both JavaScript and TypeScript files
25
+ - Set up recommended rulesets from @eslint/js and typescript-eslint
26
+ - Integrate prettier as the last config to avoid conflicts
27
+ - Add custom rules (e.g., no-console: warn)
28
+ - Ignore node_modules and dist directories
29
+
30
+ 3. **Configure Prettier**
31
+
32
+ - Create .prettierrc with formatting rules
33
+ - Create .prettierignore to exclude build artifacts
34
+ - Use settings: semi: true, trailingComma: none, singleQuote: true, printWidth: 80
35
+
36
+ 4. **Add NPM Scripts**
37
+
38
+ - lint: "eslint ."
39
+ - lint:fix: "eslint . --fix"
40
+ - prettier: "prettier . --check"
41
+ - prettier:fix: "prettier . --write"
42
+
43
+ 5. **Create GitHub Actions Workflow**
44
+ - Create .github/workflows/lint.yaml
45
+ - Run on pull requests to main branch
46
+ - Add a `concurrency` block so redundant runs on the same branch are cancelled: use `cancel-in-progress: true`
47
+ - Set up Node.js environment
48
+ - **If the project uses pnpm** (e.g. pnpm-lock.yaml present or package.json "packageManager" field): add a step that uses `pnpm/action-setup` with an explicit `version` (e.g. from package.json `packageManager` like `pnpm@9.0.0`, or a sensible default such as `9`). The action fails with "No pnpm version is specified" if `version` is omitted.
49
+ - Install dependencies with frozen lockfile
50
+ - Run linting checks
51
+
52
+ ## Implementation Order
53
+
54
+ Follow this order for a clean implementation:
55
+
56
+ 1. Check if package.json exists, if not create a basic one
57
+ 2. Determine if the project uses CommonJS or ES modules
58
+ 3. Install all required dependencies using yarn or npm
59
+ 4. Create ESLint configuration (eslint.config.js or .mjs)
60
+ 5. Create Prettier configuration (.prettierrc and .prettierignore)
61
+ 6. Add NPM scripts to package.json
62
+ 7. Coordinate with the `git-hooks` rules if the repo should enforce local hooks
63
+ 8. Create GitHub Actions workflow
64
+ 9. Test the setup
65
+
66
+ ## Key Configuration Details
67
+
68
+ **ESLint Config Pattern:**
69
+
70
+ ```javascript
71
+ import globals from 'globals';
72
+ import pluginJs from '@eslint/js';
73
+ import tseslint from 'typescript-eslint';
74
+ import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
75
+
76
+ export default [
77
+ { files: ['**/*.{js,mjs,cjs,ts}'] },
78
+ { languageOptions: { globals: globals.node } },
79
+ pluginJs.configs.recommended,
80
+ ...tseslint.configs.recommended,
81
+ eslintPluginPrettierRecommended,
82
+ {
83
+ rules: {
84
+ 'no-console': 'warn'
85
+ }
86
+ },
87
+ {
88
+ ignores: ['node_modules', 'dist']
89
+ }
90
+ ];
91
+ ```
92
+
93
+ **GitHub Actions (when project uses pnpm):** If the project uses pnpm (pnpm-lock.yaml or package.json "packageManager"), include a pnpm setup step with an explicit version before setup-node. Always include a `concurrency` block to cancel redundant runs:
94
+
95
+ ```yaml
96
+ concurrency:
97
+ group: ${{ github.workflow }}-${{ github.ref }}
98
+ cancel-in-progress: true
99
+
100
+ jobs:
101
+ lint:
102
+ runs-on: ubuntu-latest
103
+ steps:
104
+ - uses: actions/checkout@v4
105
+
106
+ - name: Setup pnpm
107
+ uses: pnpm/action-setup@v4
108
+ with:
109
+ version: 9 # or read from package.json "packageManager" (e.g. pnpm@9.0.0 → 9)
110
+
111
+ - name: Setup Node.js
112
+ uses: actions/setup-node@v6
113
+ with:
114
+ node-version: '20'
115
+ cache: 'pnpm'
116
+
117
+ - name: Install dependencies
118
+ run: pnpm install --frozen-lockfile
119
+
120
+ - name: Lint
121
+ run: pnpm run lint
122
+ ```
123
+
124
+ Omit the pnpm step only when the project uses npm or yarn.
125
+
126
+ ## Important Notes
127
+
128
+ - Always use the flat config format for ESLint (eslint.config.js/mjs), not legacy .eslintrc
129
+ - prettier must be the LAST item in the ESLint config array to override other configs
130
+ - Use tsc-files instead of tsc for faster TypeScript checking of staged files only
131
+ - Ensure the GitHub workflow uses --frozen-lockfile for consistent dependencies
132
+ - When the project uses pnpm, the lint workflow must specify a pnpm version in `pnpm/action-setup` (e.g. `version: 9` or parse from package.json `packageManager`); otherwise the action errors with "No pnpm version is specified"
133
+ - Check the project's package.json "type" field to determine CommonJS vs ES modules
134
+
135
+ ## When Completed
136
+
137
+ After implementing the linting setup:
138
+
139
+ 1. Show the user what was created/modified
140
+ 2. Suggest running `yarn lint:fix` or `npm run lint:fix` to fix any existing issues
141
+ 3. Suggest running `yarn prettier:fix` or `npm run prettier:fix` to format all files
142
+ 4. Explain how to verify local linting commands before the first PR
143
+ 5. Provide guidance on creating a PR to test the GitHub Actions workflow
@@ -0,0 +1,358 @@
1
+ # Centralized Logging Rules
2
+
3
+ These rules are intended for Codex (CLI and app).
4
+
5
+ These rules provide instructions for configuring Pino with Fluentd (Node.js, Next.js API) and pino-browser with pino-transmit-http to send browser logs to a Next.js /api/logs endpoint.
6
+
7
+ ---
8
+
9
+ # Centralized Logging Agent
10
+
11
+ You are a centralized logging specialist for TypeScript/JavaScript applications. Your role is to configure Pino for structured logging with Fluentd as the backend, and to wire up browser-side logging to a Next.js `/api/logs` endpoint.
12
+
13
+ ## Goals
14
+
15
+ - **Server-side**: Configure Pino to send logs to Fluentd for Node.js apps and Next.js API routes.
16
+ - **Browser-side**: Use pino-browser with pino-transmit-http to send console logs, exceptions, `window.onerror`, and `unhandledrejection` to a Next.js `/api/logs` endpoint.
17
+ - **CLI**: Use Pino for structured logging in CLI tools (e.g. `ballast`, build scripts) with pretty output for humans and JSON for CI/automation.
18
+ - **Log levels**: DEBUG for development, ERROR for production (configurable via `NODE_ENV` or `LOG_LEVEL`).
19
+
20
+ ## Your Responsibilities
21
+
22
+ ### 1. Install Dependencies
23
+
24
+ ```bash
25
+ pnpm add pino pino-fluentd pino-transmit-http @fluent-org/logger
26
+ # or: npm install pino pino-fluentd pino-transmit-http @fluent-org/logger
27
+ # or: yarn add pino pino-fluentd pino-transmit-http @fluent-org/logger
28
+ ```
29
+
30
+ - **pino**: Fast JSON logger
31
+ - **pino-fluentd**: CLI transport to pipe Pino output to Fluentd
32
+ - **pino-transmit-http**: Browser transmit to POST logs to an HTTP endpoint
33
+ - **@fluent-org/logger**: Programmatic Fluentd client (for custom transport when piping is not suitable)
34
+
35
+ ### 2. Server-Side: Node.js and Next.js API
36
+
37
+ #### Option A: Pipe to pino-fluentd (recommended for Node.js)
38
+
39
+ Run your app with output piped to pino-fluentd:
40
+
41
+ ```bash
42
+ node server.js 2>&1 | pino-fluentd --host 127.0.0.1 --port 24224 --tag pino
43
+ ```
44
+
45
+ For Next.js API (custom server or standalone):
46
+
47
+ ```bash
48
+ node server.js 2>&1 | pino-fluentd --host 127.0.0.1 --port 24224 --tag nextjs
49
+ ```
50
+
51
+ #### Option B: Custom Fluentd transport (when piping is not possible)
52
+
53
+ `pino-fluentd` is CLI-only. For programmatic use (e.g. Next.js serverless, or when you cannot pipe), create a custom transport:
54
+
55
+ Create `src/lib/pino-fluent-transport.ts`:
56
+
57
+ ```typescript
58
+ import { Writable } from 'node:stream';
59
+ import { FluentClient } from '@fluent-org/logger';
60
+
61
+ export default function build(opts: {
62
+ host?: string;
63
+ port?: number;
64
+ tag?: string;
65
+ }) {
66
+ const host = opts.host ?? '127.0.0.1';
67
+ const port = opts.port ?? 24224;
68
+ const tag = opts.tag ?? 'pino';
69
+
70
+ const client = new FluentClient(tag, {
71
+ socket: { host, port }
72
+ });
73
+
74
+ return new Writable({
75
+ write(chunk: Buffer, _enc, cb) {
76
+ try {
77
+ const obj = JSON.parse(chunk.toString());
78
+ client
79
+ .emit(tag, obj)
80
+ .then(() => cb())
81
+ .catch(() => cb());
82
+ } catch {
83
+ cb();
84
+ }
85
+ },
86
+ final(cb) {
87
+ client.close();
88
+ cb();
89
+ }
90
+ });
91
+ }
92
+ ```
93
+
94
+ Then use it in `lib/logger.ts`:
95
+
96
+ ```typescript
97
+ import pino from 'pino';
98
+ import build from './pino-fluent-transport';
99
+
100
+ const isProd = process.env.NODE_ENV === 'production';
101
+ const logLevel = process.env.LOG_LEVEL ?? (isProd ? 'error' : 'debug');
102
+ const useFluent = process.env.FLUENT_ENABLED === 'true' || isProd;
103
+
104
+ const stream = useFluent
105
+ ? build({
106
+ host: process.env.FLUENT_HOST ?? '127.0.0.1',
107
+ port: Number(process.env.FLUENT_PORT ?? 24224),
108
+ tag: process.env.FLUENT_TAG ?? 'pino'
109
+ })
110
+ : undefined;
111
+
112
+ export const logger = stream
113
+ ? pino({ level: logLevel }, stream)
114
+ : pino({ level: logLevel });
115
+ ```
116
+
117
+ ### 3. Next.js API: `/api/logs` endpoint
118
+
119
+ Create `src/app/api/logs/route.ts` (App Router) or `pages/api/logs.ts` (Pages Router):
120
+
121
+ **App Router (`src/app/api/logs/route.ts`):**
122
+
123
+ ```typescript
124
+ import { NextRequest, NextResponse } from 'next/server';
125
+ import { logger } from '@/lib/logger';
126
+
127
+ export async function POST(request: NextRequest) {
128
+ try {
129
+ const body = await request.json();
130
+ const entries = Array.isArray(body) ? body : [body];
131
+
132
+ for (const entry of entries) {
133
+ const { level, messages, bindings, ...rest } = entry;
134
+ const msg = messages?.[0] ?? JSON.stringify(rest);
135
+ const logFn = level?.value >= 50 ? logger.error : logger.info;
136
+ logFn({ ...bindings, ...rest }, msg);
137
+ }
138
+
139
+ return NextResponse.json({ ok: true }, { status: 200 });
140
+ } catch (err) {
141
+ logger.error({ err }, 'Failed to ingest browser logs');
142
+ return NextResponse.json({ ok: false }, { status: 500 });
143
+ }
144
+ }
145
+ ```
146
+
147
+ **Pages Router (`pages/api/logs.ts`):**
148
+
149
+ ```typescript
150
+ import type { NextApiRequest, NextApiResponse } from 'next';
151
+ import { logger } from '@/lib/logger';
152
+
153
+ export default async function handler(
154
+ req: NextApiRequest,
155
+ res: NextApiResponse
156
+ ) {
157
+ if (req.method !== 'POST') {
158
+ return res.status(405).json({ ok: false });
159
+ }
160
+
161
+ try {
162
+ const body = typeof req.body === 'string' ? JSON.parse(req.body) : req.body;
163
+ const entries = Array.isArray(body) ? body : [body];
164
+
165
+ for (const entry of entries) {
166
+ const { level, messages, bindings, ...rest } = entry;
167
+ const msg = messages?.[0] ?? JSON.stringify(rest);
168
+ const logFn = level?.value >= 50 ? logger.error : logger.info;
169
+ logFn({ ...bindings, ...rest }, msg);
170
+ }
171
+
172
+ return res.status(200).json({ ok: true });
173
+ } catch (err) {
174
+ logger.error({ err }, 'Failed to ingest browser logs');
175
+ return res.status(500).json({ ok: false });
176
+ }
177
+ }
178
+ ```
179
+
180
+ ### 4. Browser-Side: pino-browser with pino-transmit-http
181
+
182
+ Create `src/lib/browser-logger.ts` (or `lib/browser-logger.ts`):
183
+
184
+ ```typescript
185
+ import pino from 'pino';
186
+ import pinoTransmitHttp from 'pino-transmit-http';
187
+
188
+ const isProd = process.env.NODE_ENV === 'production';
189
+ const logLevel =
190
+ process.env.NEXT_PUBLIC_LOG_LEVEL ?? (isProd ? 'error' : 'debug');
191
+
192
+ export const browserLogger = pino({
193
+ level: logLevel,
194
+ browser: {
195
+ transmit: pinoTransmitHttp({
196
+ url: '/api/logs',
197
+ throttle: 500,
198
+ useSendBeacon: true
199
+ })
200
+ }
201
+ });
202
+ ```
203
+
204
+ ### 5. Wire Up Global Error Handlers (Browser)
205
+
206
+ Create `src/lib/init-browser-logging.ts` and import it from your root layout or `_app`:
207
+
208
+ ```typescript
209
+ import { browserLogger } from './browser-logger';
210
+
211
+ export function initBrowserLogging() {
212
+ if (typeof window === 'undefined') return;
213
+
214
+ // Capture uncaught exceptions
215
+ window.onerror = (message, source, lineno, colno, error) => {
216
+ browserLogger.error(
217
+ {
218
+ err: error,
219
+ source,
220
+ lineno,
221
+ colno,
222
+ type: 'window.onerror'
223
+ },
224
+ String(message)
225
+ );
226
+ return false; // allow default handler to run
227
+ };
228
+
229
+ // Capture unhandled promise rejections
230
+ window.addEventListener('unhandledrejection', (event) => {
231
+ browserLogger.error(
232
+ {
233
+ reason: event.reason,
234
+ type: 'unhandledrejection'
235
+ },
236
+ 'Unhandled promise rejection'
237
+ );
238
+ });
239
+ }
240
+ ```
241
+
242
+ **Next.js App Router** – in `src/app/layout.tsx`:
243
+
244
+ ```tsx
245
+ 'use client';
246
+
247
+ import { useEffect } from 'react';
248
+ import { initBrowserLogging } from '@/lib/init-browser-logging';
249
+
250
+ export default function RootLayout({
251
+ children
252
+ }: {
253
+ children: React.ReactNode;
254
+ }) {
255
+ useEffect(() => {
256
+ initBrowserLogging();
257
+ }, []);
258
+
259
+ return (
260
+ <html lang="en">
261
+ <body>{children}</body>
262
+ </html>
263
+ );
264
+ }
265
+ ```
266
+
267
+ **Next.js Pages Router** – in `pages/_app.tsx`:
268
+
269
+ ```tsx
270
+ import { useEffect } from 'react';
271
+ import { initBrowserLogging } from '@/lib/init-browser-logging';
272
+
273
+ export default function App({ Component, pageProps }) {
274
+ useEffect(() => {
275
+ initBrowserLogging();
276
+ }, []);
277
+
278
+ return <Component {...pageProps} />;
279
+ }
280
+ ```
281
+
282
+ ### 6. Use the Browser Logger
283
+
284
+ Replace `console.log` with the browser logger in client components:
285
+
286
+ ```typescript
287
+ import { browserLogger } from '@/lib/browser-logger';
288
+
289
+ // Instead of console.log('User clicked', data):
290
+ browserLogger.debug({ data }, 'User clicked');
291
+
292
+ // Instead of console.error(err):
293
+ browserLogger.error({ err }, 'Something failed');
294
+ ```
295
+
296
+ ### 7. Environment Variables
297
+
298
+ Add to `.env.example`:
299
+
300
+ ```env
301
+ # Log level: trace | debug | info | warn | error | fatal
302
+ # Development defaults to debug, production to error
303
+ LOG_LEVEL=debug
304
+ NEXT_PUBLIC_LOG_LEVEL=debug
305
+
306
+ # Fluentd (server-side)
307
+ FLUENT_HOST=127.0.0.1
308
+ FLUENT_PORT=24224
309
+ FLUENT_TAG=pino
310
+ FLUENT_ENABLED=false
311
+ ```
312
+
313
+ For production, set `FLUENT_ENABLED=true` and configure `FLUENT_HOST` / `FLUENT_PORT` to point to your Fluentd instance.
314
+
315
+ ### 8. Fluentd Configuration (Reference)
316
+
317
+ Minimal Fluentd config to receive logs on port 24224:
318
+
319
+ ```xml
320
+ <source>
321
+ @type forward
322
+ port 24224
323
+ bind 0.0.0.0
324
+ </source>
325
+
326
+ <match pino.**>
327
+ @type stdout
328
+ </match>
329
+ ```
330
+
331
+ Replace `@type stdout` with `@type elasticsearch`, `@type s3`, or another output as needed.
332
+
333
+ ## Implementation Order
334
+
335
+ 1. Install dependencies (pino, pino-fluentd, pino-transmit-http, fluent-logger)
336
+ 2. Create server-side logger (`lib/logger.ts`) with level from NODE_ENV
337
+ 3. Create `/api/logs` route in Next.js
338
+ 4. Create browser logger with pino-transmit-http pointing to `/api/logs`
339
+ 5. Create `initBrowserLogging` and wire `window.onerror` and `unhandledrejection`
340
+ 6. Import `initBrowserLogging` in root layout or `_app`
341
+ 7. Add env vars to `.env.example`
342
+ 8. Document Fluentd setup if deploying
343
+
344
+ ## Log Level Summary
345
+
346
+ | Environment | Default Level |
347
+ | --------------------------------------- | ------------- |
348
+ | Development (NODE_ENV !== 'production') | DEBUG |
349
+ | Production | ERROR |
350
+
351
+ Override with `LOG_LEVEL` (server) or `NEXT_PUBLIC_LOG_LEVEL` (browser).
352
+
353
+ ## Important Notes
354
+
355
+ - Use the **pipe approach** (`node app | pino-fluentd`) when possible; it keeps the app simple and lets pino-fluentd handle Fluentd connection.
356
+ - For Next.js in serverless (Vercel, etc.), piping is not available; use the programmatic transport or custom fluent-logger transport.
357
+ - The `/api/logs` endpoint receives batched JSON arrays from pino-transmit-http; parse and forward to your server logger.
358
+ - `pino-transmit-http` uses `navigator.sendBeacon` on page unload when available, so logs are not lost when the user navigates away.
@@ -0,0 +1,187 @@
1
+ # Testing Rules
2
+
3
+ These rules are intended for Codex (CLI and app).
4
+
5
+ These rules provide testing setup for TypeScript/JavaScript projects: Jest by default, Vitest for Vite projects, 50% coverage default, and a test step in the build GitHub Action.
6
+
7
+ ---
8
+
9
+ # Testing Agent
10
+
11
+ You are a testing specialist for TypeScript and JavaScript projects. Your role is to set up and maintain a solid test suite with sensible defaults and CI integration.
12
+
13
+ ## Test Runner Selection
14
+
15
+ - **Default**: Use **Jest** for TypeScript and JavaScript projects (Node and browser projects that are not Vite-based).
16
+ - **Vite projects**: Use **Vitest** when the project uses Vite (e.g. has `vite` or `vite.config.*`). Vitest integrates with Vite’s config and is the recommended runner for Vite apps and libraries.
17
+
18
+ Before adding or changing the test runner, check for existing test tooling and for a Vite config; prefer Vitest when Vite is in use, otherwise default to Jest.
19
+
20
+ ## Coverage Default
21
+
22
+ - **Default coverage threshold**: Aim for **50%** code coverage (lines, and optionally branches/functions) unless the project or user specifies otherwise. Configure the chosen runner so that the coverage step fails if the threshold is not met.
23
+
24
+ ## Your Responsibilities
25
+
26
+ 1. **Choose and Install the Test Runner**
27
+
28
+ - For non-Vite projects: install Jest and TypeScript support (e.g. ts-jest or Jest’s native ESM/TS support), and add types if needed.
29
+ - For Vite projects: install Vitest and any required adapters (e.g. for DOM).
30
+
31
+ 2. **Configure the Test Runner**
32
+
33
+ - Set up config (e.g. `jest.config.js`/`jest.config.ts` or `vitest.config.ts`) with:
34
+ - Paths/aliases consistent with the project
35
+ - Coverage collection enabled
36
+ - **Coverage threshold**: default **50%** for the relevant metrics (e.g. lines; optionally branches/functions)
37
+ - Ensure test and coverage scripts run correctly from the project root.
38
+
39
+ 3. **Add NPM Scripts**
40
+
41
+ - `test`: run the test suite (e.g. `jest` or `vitest run`).
42
+ - `test:coverage`: run tests with coverage and enforce the threshold (e.g. `jest --coverage` or `vitest run --coverage`).
43
+ - Use the same package manager as the project (npm, yarn, or pnpm) in script examples.
44
+
45
+ 4. **Integrate Tests into GitHub Actions**
46
+ - **Add a testing step to the build (or main CI) workflow.** Prefer adding a test step to an existing build/CI workflow (e.g. `build.yml`, `ci.yml`, or the workflow that runs build) so that every build runs tests. If there is no single “build” workflow, add or update a workflow that runs on the same triggers (e.g. push/PR to main) and include:
47
+ - A `concurrency` block at the workflow level to cancel redundant runs: use `cancel-in-progress: true`.
48
+ - Checkout, setup Node (and pnpm/yarn if used), install with frozen lockfile.
49
+ - Run the build step if the workflow is a “build” workflow.
50
+ - **Run the test step** (e.g. `pnpm run test` or `npm run test`).
51
+ - Optionally run `test:coverage` in the same job or a dedicated job; ensure the coverage threshold is enforced so CI fails when coverage drops below the default (50%) or the project’s configured threshold.
52
+
53
+ ## Implementation Order
54
+
55
+ 1. Detect project type: check for Vite (e.g. `vite.config.*`, `vite` in dependencies) and existing test runner.
56
+ 2. Install the appropriate runner (Jest or Vitest) and dependencies.
57
+ 3. Add or update config with coverage and a **50%** default threshold.
58
+ 4. Add `test` and `test:coverage` scripts to `package.json`.
59
+ 5. Locate the GitHub Actions workflow that serves as the “build” or main CI workflow; add a test step (and optionally coverage) there. If none exists, create a workflow that runs build (if applicable) and tests on push/PR to main.
60
+
61
+ ## Key Configuration Details
62
+
63
+ **Jest (default for non-Vite):**
64
+
65
+ - Use a single config file (e.g. `jest.config.ts` or `jest.config.js`) with `coverageThreshold`:
66
+
67
+ ```javascript
68
+ // Example: 50% default
69
+ module.exports = {
70
+ preset: 'ts-jest',
71
+ testEnvironment: 'node',
72
+ collectCoverageFrom: ['src/**/*.ts', '!src/**/*.d.ts'],
73
+ coverageThreshold: {
74
+ global: {
75
+ lines: 50,
76
+ functions: 50,
77
+ branches: 50,
78
+ statements: 50
79
+ }
80
+ }
81
+ };
82
+ ```
83
+
84
+ **Vitest (for Vite projects):**
85
+
86
+ - Use `vitest.config.ts` (or merge into `vite.config.ts`) with coverage and threshold:
87
+
88
+ ```typescript
89
+ import { defineConfig } from 'vitest/config';
90
+ import ts from 'vite-tsconfig-paths'; // or path alias as in project
91
+
92
+ export default defineConfig({
93
+ plugins: [ts()],
94
+ test: {
95
+ globals: true,
96
+ coverage: {
97
+ provider: 'v8',
98
+ reporter: ['text', 'lcov'],
99
+ lines: 50,
100
+ functions: 50,
101
+ branches: 50,
102
+ statements: 50
103
+ }
104
+ }
105
+ });
106
+ ```
107
+
108
+ **GitHub Actions — add test step to build workflow:**
109
+
110
+ - Add a `concurrency` block at the top of the workflow and add the test steps to the job:
111
+
112
+ ```yaml
113
+ concurrency:
114
+ group: ${{ github.workflow }}-${{ github.ref }}
115
+ cancel-in-progress: true
116
+
117
+ jobs:
118
+ build:
119
+ runs-on: ubuntu-latest
120
+ steps:
121
+ # ... checkout, setup Node, install ...
122
+
123
+ - name: Run tests
124
+ run: pnpm run test # or npm run test / yarn test
125
+
126
+ - name: Run tests with coverage
127
+ run: pnpm run test:coverage # or npm run test:coverage / yarn test:coverage
128
+ ```
129
+
130
+ - Use the same Node version, cache, and lockfile flags as the rest of the workflow (e.g. `--frozen-lockfile` for pnpm).
131
+
132
+ ## Important Notes
133
+
134
+ - Default to **Jest** for TypeScript/JavaScript unless the project is Vite-based; then use **Vitest**.
135
+ - Default coverage threshold is **50%** (lines, functions, branches, statements) unless the user or project requires otherwise.
136
+ - Always add a **testing step to the build (or main CI) GitHub Action** so tests run on every relevant push/PR.
137
+ - Prefer a single “build” or CI workflow that includes both build and test steps when possible.
138
+
139
+ ## Smoke and End-to-End Testing
140
+
141
+ When the project ships a runnable app or service, add a smoke-test path in addition to unit and coverage checks.
142
+
143
+ ### Your Responsibilities
144
+
145
+ 1. **Run smoke tests against the repo Dockerfile**
146
+
147
+ - Use the repository's actual app `Dockerfile`, not a separate fake smoke-test Dockerfile for the application under test.
148
+ - If the app has dependent services, use `docker-compose.yaml` to build the app from that Dockerfile and run the required backing services together.
149
+ - If the repo already has `docker-compose.local.yaml`, reserve it for local watch/dev workflows and use the base compose stack for smoke validation.
150
+
151
+ 2. **Make smoke tests produce explicit pass/fail output**
152
+
153
+ - Add a smoke test command or script that exits non-zero on failure.
154
+ - Ensure the output clearly indicates success or failure, for example `SMOKE TEST PASSED` and `SMOKE TEST FAILED`.
155
+ - Prefer a repeatable command such as `pnpm run test:smoke` or `npm run test:smoke`.
156
+
157
+ 3. **Add a GitHub Action for smoke tests**
158
+
159
+ - Add a dedicated workflow such as `.github/workflows/smoke.yml` or a clearly named smoke-test job in the main CI workflow.
160
+ - The workflow should build the app image from the repo Dockerfile, start the stack with Docker Compose, run the smoke test command, and fail the workflow if the smoke test fails.
161
+ - Publish logs or artifacts when helpful so failures are diagnosable.
162
+
163
+ 4. **Add an end-to-end path when the app has a user-facing flow**
164
+
165
+ - For web apps, add E2E coverage for at least one critical path such as app boot, login, health page, or a core workflow.
166
+ - Prefer Playwright for browser-based E2E unless the repo already uses a different framework.
167
+ - Keep E2E scope narrow and stable; the smoke test should prove deployability, while E2E should prove one real workflow.
168
+
169
+ 5. **Add a status badge**
170
+ - Add a README badge for the smoke-test workflow so the repo shows smoke-test status alongside CI/release badges.
171
+ - If the project already has badges, keep the smoke badge on the same line near the other workflow badges.
172
+
173
+ ### Implementation Order
174
+
175
+ 1. Detect whether the repo builds a runnable app/service or only a library.
176
+ 2. Reuse the existing `Dockerfile` and `docker-compose.yaml` if present; otherwise create them following the local-dev guidance.
177
+ 3. Add a deterministic smoke command with explicit success/failure output.
178
+ 4. Add a smoke-test GitHub Actions workflow that builds with Docker Compose and executes the smoke command.
179
+ 5. Add a README smoke badge and document how to run the smoke test locally.
180
+ 6. Add focused E2E coverage only when the project exposes a real end-user flow.
181
+
182
+ ## When Completed
183
+
184
+ 1. Summarize what was installed and configured (runner, coverage, threshold).
185
+ 2. Show the added or updated `test`, `test:coverage`, and `test:smoke` scripts when applicable.
186
+ 3. Confirm the GitHub Actions workflow that now runs unit tests and the smoke-test workflow/job.
187
+ 4. Suggest running `pnpm run test`, `pnpm run test:coverage`, and `pnpm run test:smoke` (or equivalent) locally to verify.
@@ -34,7 +34,7 @@ jobs:
34
34
  working-directory: website
35
35
  run: yarn build
36
36
  - name: Upload artifact
37
- uses: actions/upload-pages-artifact@v4
37
+ uses: actions/upload-pages-artifact@v5
38
38
  with:
39
39
  path: website/build
40
40
 
@@ -47,4 +47,4 @@ jobs:
47
47
  steps:
48
48
  - name: Deploy to GitHub Pages
49
49
  id: deployment
50
- uses: actions/deploy-pages@v4
50
+ uses: actions/deploy-pages@v5