@pikku/cli 0.12.69 → 0.12.71

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 (115) hide show
  1. package/cli.schema.json +1 -1
  2. package/console-app/assets/{index-BY60UXB6.js → index-Bn7IPpsQ.js} +140 -141
  3. package/console-app/index.html +1 -1
  4. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
  5. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
  6. package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
  7. package/dist/.pikku/cli/pikku-cli-channel.js +6 -11
  8. package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
  9. package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
  10. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
  11. package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
  12. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
  13. package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
  14. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
  15. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +27 -31
  16. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
  17. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
  18. package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
  19. package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
  20. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  21. package/dist/.pikku/function/pikku-function-types.gen.d.ts +1 -1
  22. package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
  23. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  24. package/dist/.pikku/function/pikku-functions-meta.gen.json +48 -43
  25. package/dist/.pikku/function/pikku-functions.gen.js +3 -1
  26. package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
  27. package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
  28. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +1 -1
  29. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +1 -1
  30. package/dist/.pikku/http/pikku-http-wirings.gen.js +1 -1
  31. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
  32. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
  33. package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
  34. package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
  35. package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
  36. package/dist/.pikku/pikku-meta-service.gen.js +1 -1
  37. package/dist/.pikku/pikku-services.gen.d.ts +4 -2
  38. package/dist/.pikku/pikku-services.gen.js +2 -0
  39. package/dist/.pikku/pikku-types.gen.d.ts +1 -1
  40. package/dist/.pikku/pikku-types.gen.js +1 -1
  41. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
  42. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
  43. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
  44. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
  45. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
  46. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
  47. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +2 -2
  48. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
  49. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
  50. package/dist/.pikku/schemas/register.gen.js +3 -5
  51. package/dist/.pikku/schemas/schemas/DevInput.schema.json +1 -1
  52. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  53. package/dist/.pikku/schemas/schemas/PikkuScenarioFunctionsOutput.schema.json +1 -0
  54. package/dist/.pikku/schemas/schemas/ScenarioRunInput.schema.json +1 -1
  55. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
  56. package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
  57. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
  58. package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
  59. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  60. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  61. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
  62. package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
  63. package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
  64. package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
  65. package/dist/.pikku/workflow/meta/allWorkflow.gen.json +8 -2
  66. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
  67. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
  68. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  69. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  70. package/dist/bin/pikku-bin.mjs +2 -2
  71. package/dist/src/cli.wiring.js +27 -29
  72. package/dist/src/fabric/fabric-commands.d.ts +3 -3
  73. package/dist/src/fabric/functions/llm-key.function.d.ts +4 -4
  74. package/dist/src/fabric/functions/validate.function.js +54 -15
  75. package/dist/src/functions/commands/all.js +14 -1
  76. package/dist/src/functions/commands/bun-coverage-loader.d.ts +11 -0
  77. package/dist/src/functions/commands/bun-coverage-loader.js +42 -0
  78. package/dist/src/functions/commands/dev.d.ts +6 -0
  79. package/dist/src/functions/commands/dev.js +19 -4
  80. package/dist/src/functions/commands/enable.d.ts +1 -0
  81. package/dist/src/functions/commands/enable.js +9 -1
  82. package/dist/src/functions/commands/scenario.d.ts +3 -0
  83. package/dist/src/functions/commands/scenario.js +52 -11
  84. package/dist/src/functions/commands/serve.js +4 -1
  85. package/dist/src/functions/commands/start-coverage.d.ts +13 -0
  86. package/dist/src/functions/commands/start-coverage.js +42 -0
  87. package/dist/src/functions/commands/watch.js +2 -1
  88. package/dist/src/functions/validate/workspace-validate.js +0 -4
  89. package/dist/src/functions/wirings/console/serialize-console-functions.js +0 -6
  90. package/dist/src/functions/wirings/scenarios/pikku-command-scenario-functions.d.ts +1 -0
  91. package/dist/src/functions/wirings/scenarios/pikku-command-scenario-functions.js +25 -0
  92. package/dist/src/functions/wirings/scenarios/serialize-scenario-functions.d.ts +6 -0
  93. package/dist/src/functions/wirings/scenarios/serialize-scenario-functions.js +98 -0
  94. package/dist/src/functions/wirings/workflow/pikku-command-workflow.js +4 -5
  95. package/dist/src/functions/wirings/workflow/serialize-scenario-actors.d.ts +0 -6
  96. package/dist/src/functions/wirings/workflow/serialize-scenario-actors.js +1 -15
  97. package/dist/src/functions/workflows/all.workflow.js +6 -0
  98. package/dist/src/services.js +14 -1
  99. package/dist/src/utils/file-writer.d.ts +1 -0
  100. package/dist/src/utils/file-writer.js +9 -0
  101. package/dist/src/utils/meta-diff.d.ts +32 -0
  102. package/dist/src/utils/meta-diff.js +144 -0
  103. package/dist/src/utils/pikku-cli-config.js +3 -0
  104. package/dist/src/utils/precise-coverage-map.d.ts +4 -0
  105. package/dist/src/utils/precise-coverage-map.js +176 -0
  106. package/dist/src/utils/serialize-schemas.js +1 -1
  107. package/dist/src/utils/strip-verbose-meta.js +3 -0
  108. package/dist/tsconfig.tsbuildinfo +1 -1
  109. package/package.json +9 -3
  110. package/dist/.pikku/schemas/schemas/PikkuTestsCoverageInput.schema.json +0 -1
  111. package/dist/.pikku/schemas/schemas/PikkuTestsInitInput.schema.json +0 -1
  112. package/dist/src/functions/commands/tests-coverage.d.ts +0 -10
  113. package/dist/src/functions/commands/tests-coverage.js +0 -273
  114. package/dist/src/functions/commands/tests-init.d.ts +0 -7
  115. package/dist/src/functions/commands/tests-init.js +0 -274
@@ -1,274 +0,0 @@
1
- import { existsSync } from 'fs';
2
- import { mkdir, writeFile } from 'fs/promises';
3
- import { dirname, join, relative } from 'path';
4
- import { pikkuSessionlessFunc } from '#pikku';
5
- const toJs = (p) => p.replace(/\.(?:d\.)?ts$/, '.js');
6
- // ---------------------------------------------------------------------------
7
- // Template generators
8
- // ---------------------------------------------------------------------------
9
- function packageJson() {
10
- return JSON.stringify({
11
- name: 'tests',
12
- version: '0.0.1',
13
- private: true,
14
- type: 'module',
15
- description: 'Function test harness — Cucumber over in-process Pikku RPC with stubbed services.',
16
- scripts: {
17
- test: "node --env-file=.env.test node_modules/.bin/cucumber-js --config tests/cucumber.mjs --tags 'not @skip'",
18
- 'test:tag': 'node --env-file=.env.test node_modules/.bin/cucumber-js --config tests/cucumber.mjs --tags',
19
- coverage: 'pikku tests coverage',
20
- tsc: 'tsc --noEmit',
21
- },
22
- dependencies: {
23
- '@pikku/cucumber': '^0.12.0',
24
- '@pikku/kysely-node-sqlite': '^0.12.0',
25
- },
26
- devDependencies: {
27
- '@cucumber/cucumber': '^11.0.0',
28
- '@types/node': '^22',
29
- c8: '^10.0.0',
30
- tsx: '^4.21.0',
31
- typescript: '~5.8.0',
32
- },
33
- }, null, 2);
34
- }
35
- function tsconfig() {
36
- return JSON.stringify({
37
- compilerOptions: {
38
- target: 'ES2022',
39
- module: 'NodeNext',
40
- moduleResolution: 'NodeNext',
41
- types: ['node'],
42
- noEmit: true,
43
- skipLibCheck: true,
44
- esModuleInterop: true,
45
- resolveJsonModule: true,
46
- strict: true,
47
- },
48
- include: ['tests/**/*.ts'],
49
- }, null, 2);
50
- }
51
- function envTest() {
52
- return `# Environment variables required by createConfig() during tests.
53
- # Add any env vars your config.ts reads at module load time.
54
- # This file is loaded via --env-file and is NOT committed to version control.
55
- NODE_ENV=test
56
- `;
57
- }
58
- function cucumberMjs() {
59
- return `export default {
60
- requireModule: ['tsx'],
61
- require: ['tests/support/**/*.ts', 'tests/steps/**/*.ts'],
62
- paths: ['tests/features/**/*.feature'],
63
- format: ['progress', 'html:tests/reports/cucumber-report.html'],
64
- forceExit: true,
65
- }
66
- `;
67
- }
68
- function hooksTs(bootstrapImport) {
69
- return `import '${bootstrapImport}'
70
- import { Before, After, BeforeAll, AfterAll, setDefaultTimeout, Given, When, Then } from '@cucumber/cucumber'
71
- import { registerHooks, registerCommonSteps } from '@pikku/cucumber'
72
- import { db } from './services.js'
73
-
74
- registerHooks({ Before, After, BeforeAll, AfterAll, setDefaultTimeout }, db)
75
- registerCommonSteps({ Given, When, Then })
76
- `;
77
- }
78
- function starterFeature() {
79
- return `Feature: Example function test
80
-
81
- Starter scenario created by \`pikku tests init\`. It uses only the built-in
82
- pikku/cucumber steps (no custom step code) and passes out of the box, so the
83
- Run-tests button and coverage report work immediately. Replace it with real
84
- scenarios that call your RPCs — see the commented example at the bottom.
85
-
86
- Scenario: the function-test harness is wired up
87
- Given the data "example" is:
88
- | hello | world |
89
- Then the data "example" is not empty
90
-
91
- # Real example — call one of your RPCs and assert the outcome. Uncomment and
92
- # adapt (run \`pikku meta\` to list versioned RPC names and input schemas):
93
- #
94
- # Scenario: an anonymous user cannot reach a protected RPC
95
- # When an anonymous user calls "yourProtectedRpc"
96
- # Then the call fails with "Unauthorized"
97
- #
98
- # Scenario: a public RPC returns data
99
- # When an anonymous user calls "yourPublicRpc" with:
100
- # | someField | someValue |
101
- # Then the call succeeds
102
- # And the result has "id"
103
- `;
104
- }
105
- function worldTs() {
106
- return `import { World, setWorldConstructor } from '@cucumber/cucumber'
107
- import { createFunctionWorld } from '@pikku/cucumber'
108
- import { createStubServices } from './services.js'
109
-
110
- createFunctionWorld(World, setWorldConstructor, createStubServices)
111
- `;
112
- }
113
- function servicesTs(configImport, servicesImport, schemaImport, coercionImport, configVar, servicesVar, repoRootRel, hasDb, migrationsRel, seedRel) {
114
- if (!hasDb) {
115
- return `import { createDbUtils, type StubTracker } from '@pikku/cucumber'
116
- import { ${configVar} } from '${configImport}'
117
- import { ${servicesVar} } from '${servicesImport}'
118
-
119
- export const db = createDbUtils({ migrationsDir: '', seedFile: '' })
120
-
121
- export async function createStubServices(_dbFile: string, tracker: StubTracker) {
122
- const injected = new Proxy({} as Record<string, unknown>, {
123
- get(_, prop: string) { return tracker.stub(prop) },
124
- })
125
- const config = await ${configVar}()
126
- const services = await ${servicesVar}(config as never, injected as never)
127
- return { services }
128
- }
129
- `;
130
- }
131
- return `import { createNodeSqliteKysely, createCoercionPlugin } from '@pikku/kysely-node-sqlite'
132
- import { createDbUtils, type StubTracker } from '@pikku/cucumber'
133
- import { ${configVar} } from '${configImport}'
134
- import { ${servicesVar} } from '${servicesImport}'
135
- import { coercionMap } from '${coercionImport}'
136
- import type { DB } from '${schemaImport}'
137
- import { dirname, resolve } from 'node:path'
138
- import { fileURLToPath } from 'node:url'
139
-
140
- const __dirname = dirname(fileURLToPath(import.meta.url))
141
- const repoRoot = (p: string) => resolve(__dirname, '${repoRootRel}', p)
142
-
143
- export const db = createDbUtils({
144
- migrationsDir: repoRoot('${migrationsRel}'),
145
- seedFile: repoRoot('${seedRel}'),
146
- })
147
-
148
- type StubKysely = ReturnType<typeof createNodeSqliteKysely<DB>>
149
-
150
- const REAL_SERVICES = (kysely: StubKysely) => ({ kysely })
151
-
152
- export async function createStubServices(dbFile: string, tracker: StubTracker) {
153
- const kysely = createNodeSqliteKysely<DB>({
154
- filename: dbFile,
155
- camelCase: true,
156
- plugins: [createCoercionPlugin({ map: coercionMap })],
157
- })
158
-
159
- const real = REAL_SERVICES(kysely)
160
- const injected = new Proxy(real as Record<string, unknown>, {
161
- get(target, prop: string) {
162
- if (prop in target) return target[prop]
163
- return tracker.stub(prop)
164
- },
165
- })
166
-
167
- const config = await ${configVar}()
168
- const services = await ${servicesVar}(
169
- { ...config, dev: { db: { file: dbFile } } } as never,
170
- injected as never,
171
- )
172
-
173
- return { services, kysely }
174
- }
175
- `;
176
- }
177
- // ---------------------------------------------------------------------------
178
- // Command
179
- // ---------------------------------------------------------------------------
180
- export const pikkuTestsInit = pikkuSessionlessFunc({
181
- func: async ({ logger, config, getInspectorState }, input) => {
182
- const force = input?.force;
183
- const state = await getInspectorState(true);
184
- const { pikkuConfigFactory, singletonServicesFactory } = state.filesAndMethods;
185
- if (!pikkuConfigFactory) {
186
- logger.error('createConfig not found — ensure it is exported from your project');
187
- process.exit(1);
188
- }
189
- if (!singletonServicesFactory) {
190
- logger.error('createSingletonServices not found — ensure it is exported from your project');
191
- process.exit(1);
192
- }
193
- const packageMappings = config.packageMappings ?? {};
194
- const srcDirs = config.srcDirectories ?? [];
195
- const functionsRelDir = Object.keys(packageMappings).find((key) => srcDirs.some((src) => src === key || src.startsWith(key + '/'))) ?? Object.keys(packageMappings)[0];
196
- if (!functionsRelDir) {
197
- logger.error('packageMappings must have at least one entry pointing to your functions package');
198
- process.exit(1);
199
- }
200
- const functionsDir = join(config.rootDir, functionsRelDir);
201
- const ftestDir = join(functionsDir, 'tests');
202
- if (existsSync(ftestDir) && !force) {
203
- logger.error(`tests directory already exists at ${ftestDir}. Use --force to overwrite.`);
204
- process.exit(1);
205
- }
206
- const supportDir = join(ftestDir, 'tests', 'support');
207
- const rel = (abs) => {
208
- const r = relative(supportDir, abs);
209
- return r.startsWith('.') ? r : './' + r;
210
- };
211
- const bootstrapImport = toJs(rel(join(config.outDir, 'pikku-bootstrap.gen.ts')));
212
- const configImport = toJs(rel(pikkuConfigFactory.file));
213
- const servicesImport = toJs(rel(singletonServicesFactory.file));
214
- // coercion/schema may live under outDir/db (new default) or rootDir/db (legacy)
215
- const schemaInOutDir = join(config.outDir, 'db', 'schema.gen.ts');
216
- const schemaInRootDir = join(config.rootDir, 'db', 'schema.gen.ts');
217
- const schemaFile = existsSync(schemaInOutDir)
218
- ? schemaInOutDir
219
- : schemaInRootDir;
220
- const coercionInOutDir = join(config.outDir, 'db', 'coercion.gen.ts');
221
- const coercionInRootDir = join(config.rootDir, 'db', 'coercion.gen.ts');
222
- const coercionFile = existsSync(coercionInOutDir)
223
- ? coercionInOutDir
224
- : coercionInRootDir;
225
- const schemaImport = toJs(rel(schemaFile));
226
- const coercionImport = toJs(rel(coercionFile));
227
- const repoRootRel = relative(supportDir, config.rootDir);
228
- // Engine-aware db layout: stages live under db/sqlite or db/postgres with a
229
- // matching db/<engine>-seed.sql (see the deploy convention). Pick whichever
230
- // engine the project actually ships migrations for.
231
- const engine = existsSync(join(config.rootDir, 'db', 'sqlite'))
232
- ? 'sqlite'
233
- : existsSync(join(config.rootDir, 'db', 'postgres'))
234
- ? 'postgres'
235
- : null;
236
- // Only sqlite runs in the harness today (node:sqlite); postgres falls back
237
- // to stubbed services until a pglite-backed harness lands.
238
- const hasDb = engine === 'sqlite';
239
- const migrationsRel = engine ? `db/${engine}` : '';
240
- const seedRel = engine ? `db/${engine}-seed.sql` : '';
241
- if (engine === 'postgres') {
242
- logger.info('Note: Postgres function-test harness support is not wired yet (the harness runs on node:sqlite). Tracking in pikkujs/pikku#758 — the scaffold falls back to stubbed services.');
243
- }
244
- const files = [
245
- [join(ftestDir, '.env.test'), envTest()],
246
- // Empty lockfile so Yarn Berry treats tests/ as a standalone project
247
- // rather than expecting it in the parent repo's workspaces (the harness
248
- // is intentionally outside the workspace graph).
249
- [join(ftestDir, 'yarn.lock'), ''],
250
- [join(ftestDir, 'package.json'), packageJson()],
251
- [join(ftestDir, 'tsconfig.json'), tsconfig()],
252
- [join(ftestDir, 'tests', 'cucumber.mjs'), cucumberMjs()],
253
- [join(supportDir, 'hooks.ts'), hooksTs(bootstrapImport)],
254
- [join(supportDir, 'world.ts'), worldTs()],
255
- [
256
- join(supportDir, 'services.ts'),
257
- servicesTs(configImport, servicesImport, schemaImport, coercionImport, pikkuConfigFactory.variable, singletonServicesFactory.variable, repoRootRel, hasDb, migrationsRel, seedRel),
258
- ],
259
- [
260
- join(ftestDir, 'tests', 'features', 'example.feature'),
261
- starterFeature(),
262
- ],
263
- ];
264
- for (const [filePath, content] of files) {
265
- await mkdir(dirname(filePath), { recursive: true });
266
- await writeFile(filePath, content, 'utf-8');
267
- logger.info(` created ${relative(config.rootDir, filePath)}`);
268
- }
269
- logger.info('\nFunction test harness initialized.');
270
- logger.info('Next steps:');
271
- logger.info(' 1. Install deps in tests/ and run: yarn test');
272
- logger.info(' 2. Edit tests/tests/features/example.feature — add scenarios that call your RPCs');
273
- },
274
- });