@granular-software/fractory 0.0.0-stage → 0.1.24
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.
- package/LICENSE +4 -0
- package/README.md +28 -2
- package/dist/activity-volume.d.ts +18 -0
- package/dist/activity-volume.js +94 -0
- package/dist/annotations.d.ts +118 -0
- package/dist/annotations.js +304 -0
- package/dist/benchmark-cli.d.ts +1 -0
- package/dist/benchmark-cli.js +95 -0
- package/dist/benchmark-worker.d.ts +2 -0
- package/dist/benchmark-worker.js +22 -0
- package/dist/benchmarks.d.ts +19 -0
- package/dist/benchmarks.js +414 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +63 -0
- package/dist/block-cli.d.ts +1 -0
- package/dist/block-cli.js +88 -0
- package/dist/block-documents.d.ts +35 -0
- package/dist/block-documents.js +84 -0
- package/dist/change-impact.d.ts +55 -0
- package/dist/change-impact.js +223 -0
- package/dist/check-source.d.ts +2 -0
- package/dist/check-source.js +66 -0
- package/dist/checks-model.d.ts +64 -0
- package/dist/checks-model.js +36 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +359 -0
- package/dist/code-model.d.ts +38 -0
- package/dist/code-model.js +94 -0
- package/dist/code-store.d.ts +9 -0
- package/dist/code-store.js +79 -0
- package/dist/compare-artifact.d.ts +6 -0
- package/dist/compare-artifact.js +277 -0
- package/dist/compare.d.ts +81 -0
- package/dist/compare.js +291 -0
- package/dist/compiler.d.ts +10 -0
- package/dist/compiler.js +1083 -0
- package/dist/compose.d.ts +9 -0
- package/dist/compose.js +72 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +206 -0
- package/dist/coverage-cli.d.ts +1 -0
- package/dist/coverage-cli.js +42 -0
- package/dist/declaration-sources.d.ts +3 -0
- package/dist/declaration-sources.js +51 -0
- package/dist/declared-graph.d.ts +3 -0
- package/dist/declared-graph.js +66 -0
- package/dist/display-name.d.ts +2 -0
- package/dist/display-name.js +8 -0
- package/dist/error-heat.d.ts +58 -0
- package/dist/error-heat.js +96 -0
- package/dist/evidence.d.ts +3 -0
- package/dist/evidence.js +68 -0
- package/dist/factory-graph.d.ts +4 -0
- package/dist/factory-graph.js +318 -0
- package/dist/factory-model.d.ts +97 -0
- package/dist/factory-model.js +1 -0
- package/dist/git-code.d.ts +47 -0
- package/dist/git-code.js +352 -0
- package/dist/git-refs.d.ts +4 -0
- package/dist/git-refs.js +37 -0
- package/dist/history-activity.d.ts +4 -0
- package/dist/history-activity.js +129 -0
- package/dist/history-churn.d.ts +36 -0
- package/dist/history-churn.js +302 -0
- package/dist/history-git.d.ts +21 -0
- package/dist/history-git.js +125 -0
- package/dist/history-ledger.d.ts +43 -0
- package/dist/history-ledger.js +450 -0
- package/dist/history-ownership.d.ts +10 -0
- package/dist/history-ownership.js +75 -0
- package/dist/history-source.d.ts +13 -0
- package/dist/history-source.js +100 -0
- package/dist/integrations-cli.d.ts +2 -0
- package/dist/integrations-cli.js +159 -0
- package/dist/issue-cache.d.ts +9 -0
- package/dist/issue-cache.js +68 -0
- package/dist/issue-cli.d.ts +1 -0
- package/dist/issue-cli.js +89 -0
- package/dist/issue-links.d.ts +15 -0
- package/dist/issue-links.js +125 -0
- package/dist/linear-issues.d.ts +19 -0
- package/dist/linear-issues.js +124 -0
- package/dist/local-runtime.d.ts +8 -0
- package/dist/local-runtime.js +59 -0
- package/dist/map-activity.d.ts +73 -0
- package/dist/map-activity.js +234 -0
- package/dist/map-model.d.ts +5 -0
- package/dist/map-model.js +166 -0
- package/dist/map-quality.d.ts +14 -0
- package/dist/map-quality.js +56 -0
- package/dist/mapping-coverage.d.ts +87 -0
- package/dist/mapping-coverage.js +404 -0
- package/dist/model.d.ts +182 -0
- package/dist/model.js +66 -0
- package/dist/operation-benchmark-worker.d.ts +2 -0
- package/dist/operation-benchmark-worker.js +60 -0
- package/dist/operation-benchmark.d.ts +29 -0
- package/dist/operation-benchmark.js +1 -0
- package/dist/otel-metrics.d.ts +21 -0
- package/dist/otel-metrics.js +146 -0
- package/dist/performance-model.d.ts +185 -0
- package/dist/performance-model.js +396 -0
- package/dist/product-map.d.ts +69 -0
- package/dist/product-map.js +168 -0
- package/dist/provider-access.cjs +207 -0
- package/dist/provider-access.d.cts +14 -0
- package/dist/reports-cli.d.ts +1 -0
- package/dist/reports-cli.js +111 -0
- package/dist/reports-model.d.ts +27 -0
- package/dist/reports-model.js +39 -0
- package/dist/reports.d.ts +23 -0
- package/dist/reports.js +223 -0
- package/dist/repository-map.d.ts +22 -0
- package/dist/repository-map.js +151 -0
- package/dist/resource-cache.d.ts +17 -0
- package/dist/resource-cache.js +65 -0
- package/dist/review-cli.d.ts +19 -0
- package/dist/review-cli.js +224 -0
- package/dist/review.d.ts +48 -0
- package/dist/review.js +289 -0
- package/dist/runtime-metrics.d.ts +26 -0
- package/dist/runtime-metrics.js +290 -0
- package/dist/scope.d.ts +12 -0
- package/dist/scope.js +94 -0
- package/dist/sentry-activity.d.ts +39 -0
- package/dist/sentry-activity.js +174 -0
- package/dist/sentry.d.ts +130 -0
- package/dist/sentry.js +369 -0
- package/dist/service-release.d.ts +16 -0
- package/dist/service-release.js +14 -0
- package/dist/setup-cli.d.ts +2 -0
- package/dist/setup-cli.js +52 -0
- package/dist/setup-kit.cjs +163 -0
- package/dist/setup-kit.d.cts +32 -0
- package/dist/source-index.d.ts +37 -0
- package/dist/source-index.js +166 -0
- package/dist/source-review-git.d.ts +7 -0
- package/dist/source-review-git.js +103 -0
- package/dist/source-review.d.ts +16 -0
- package/dist/source-review.js +493 -0
- package/dist/telemetry.d.ts +17 -0
- package/dist/telemetry.js +51 -0
- package/dist/time-window.d.ts +9 -0
- package/dist/time-window.js +35 -0
- package/dist/trace-evidence.d.ts +23 -0
- package/dist/trace-evidence.js +55 -0
- package/dist/trace-model.d.ts +26 -0
- package/dist/trace-model.js +1 -0
- package/dist/tracing.d.ts +44 -0
- package/dist/tracing.js +123 -0
- package/dist/work-check.d.ts +17 -0
- package/dist/work-check.js +110 -0
- package/dist/work-cli.d.ts +1 -0
- package/dist/work-cli.js +148 -0
- package/dist/work-context.d.ts +57 -0
- package/dist/work-context.js +568 -0
- package/dist/work-intents.d.ts +6 -0
- package/dist/work-intents.js +140 -0
- package/dist/work-items.d.ts +58 -0
- package/dist/work-items.js +86 -0
- package/dist/work-model.d.ts +110 -0
- package/dist/work-model.js +261 -0
- package/dist/work-review-git.d.ts +8 -0
- package/dist/work-review-git.js +111 -0
- package/dist/work-review.d.ts +26 -0
- package/dist/work-review.js +426 -0
- package/dist/work-switcher-model.d.ts +43 -0
- package/dist/work-switcher-model.js +79 -0
- package/dist/work-switcher.d.ts +6 -0
- package/dist/work-switcher.js +171 -0
- package/dist/working-cli.d.ts +1 -0
- package/dist/working-cli.js +33 -0
- package/dist/working-code.d.ts +74 -0
- package/dist/working-code.js +421 -0
- package/dist/workspace-notes.d.ts +71 -0
- package/dist/workspace-notes.js +177 -0
- package/dist/workspace-tests.d.ts +21 -0
- package/dist/workspace-tests.js +573 -0
- package/package.json +547 -4
- package/src/activity-volume.ts +149 -0
- package/src/annotations.ts +481 -0
- package/src/benchmark-cli.ts +118 -0
- package/src/benchmark-worker.ts +22 -0
- package/src/benchmarks.ts +493 -0
- package/src/bin.ts +54 -0
- package/src/block-cli.ts +106 -0
- package/src/block-documents.ts +117 -0
- package/src/change-impact.ts +280 -0
- package/src/check-source.ts +82 -0
- package/src/checks-model.ts +108 -0
- package/src/cli.ts +440 -0
- package/src/code-model.ts +159 -0
- package/src/code-store.ts +98 -0
- package/src/compare-artifact.ts +314 -0
- package/src/compare.ts +440 -0
- package/src/compiler.ts +1326 -0
- package/src/compose.ts +94 -0
- package/src/core.ts +357 -0
- package/src/coverage-cli.ts +52 -0
- package/src/declaration-sources.ts +69 -0
- package/src/declared-graph.ts +74 -0
- package/src/display-name.ts +8 -0
- package/src/error-heat.ts +161 -0
- package/src/evidence.ts +94 -0
- package/src/factory-graph.ts +378 -0
- package/src/factory-model.ts +73 -0
- package/src/git-code.ts +461 -0
- package/src/git-refs.ts +43 -0
- package/src/history-activity.ts +146 -0
- package/src/history-churn.ts +416 -0
- package/src/history-git.ts +163 -0
- package/src/history-ledger.ts +636 -0
- package/src/history-ownership.ts +116 -0
- package/src/history-source.ts +117 -0
- package/src/integrations-cli.ts +187 -0
- package/src/issue-cache.ts +96 -0
- package/src/issue-cli.ts +137 -0
- package/src/issue-links.ts +153 -0
- package/src/linear-issues.ts +154 -0
- package/src/local-runtime.ts +70 -0
- package/src/map-activity.ts +309 -0
- package/src/map-model.ts +213 -0
- package/src/map-quality.ts +61 -0
- package/src/mapping-coverage.ts +570 -0
- package/src/model.ts +221 -0
- package/src/operation-benchmark-worker.ts +60 -0
- package/src/operation-benchmark.ts +28 -0
- package/src/otel-metrics.ts +176 -0
- package/src/performance-model.ts +575 -0
- package/src/product-map.ts +236 -0
- package/src/provider-access.cjs +207 -0
- package/src/provider-access.d.cts +14 -0
- package/src/reports-cli.ts +125 -0
- package/src/reports-model.ts +73 -0
- package/src/reports.ts +276 -0
- package/src/repository-map.ts +189 -0
- package/src/resource-cache.ts +76 -0
- package/src/review-cli.ts +256 -0
- package/src/review.ts +376 -0
- package/src/runtime-metrics.ts +386 -0
- package/src/scope.ts +103 -0
- package/src/sentry-activity.ts +234 -0
- package/src/sentry.ts +545 -0
- package/src/service-release.ts +18 -0
- package/src/setup-cli.ts +58 -0
- package/src/setup-kit.cjs +163 -0
- package/src/setup-kit.d.cts +32 -0
- package/src/source-index.ts +205 -0
- package/src/source-review-git.ts +129 -0
- package/src/source-review.ts +637 -0
- package/src/telemetry.ts +68 -0
- package/src/time-window.ts +51 -0
- package/src/trace-evidence.ts +80 -0
- package/src/trace-model.ts +26 -0
- package/src/tracing.ts +165 -0
- package/src/work-check.ts +143 -0
- package/src/work-cli.ts +195 -0
- package/src/work-context.ts +713 -0
- package/src/work-intents.ts +196 -0
- package/src/work-items.ts +151 -0
- package/src/work-model.ts +400 -0
- package/src/work-review-git.ts +130 -0
- package/src/work-review.ts +573 -0
- package/src/work-switcher-model.ts +121 -0
- package/src/work-switcher.ts +191 -0
- package/src/working-cli.ts +38 -0
- package/src/working-code.ts +582 -0
- package/src/workspace-notes.ts +203 -0
- package/src/workspace-tests.ts +654 -0
- package/toolkit/GUIDE.md +305 -0
- package/toolkit/SKILL.md +131 -0
- package/toolkit/bin/fractory +2 -0
- package/toolkit/build.json +1 -0
package/dist/model.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/** Lift a connection to the nearest visible ancestor, preserving its original identity. */
|
|
2
|
+
export function projectGraph(graph, expanded) {
|
|
3
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
4
|
+
const visible = (node) => !node.parent ||
|
|
5
|
+
(expanded.has(node.parent) &&
|
|
6
|
+
!!byId.get(node.parent) &&
|
|
7
|
+
visible(byId.get(node.parent)));
|
|
8
|
+
const nodes = graph.elements.filter(visible);
|
|
9
|
+
const shown = new Set(nodes.map((n) => n.id));
|
|
10
|
+
const ancestor = (id) => {
|
|
11
|
+
const seen = new Set();
|
|
12
|
+
while (!shown.has(id)) {
|
|
13
|
+
if (seen.has(id))
|
|
14
|
+
return;
|
|
15
|
+
seen.add(id);
|
|
16
|
+
const parent = byId.get(id)?.parent;
|
|
17
|
+
if (!parent)
|
|
18
|
+
return;
|
|
19
|
+
id = parent;
|
|
20
|
+
}
|
|
21
|
+
return id;
|
|
22
|
+
};
|
|
23
|
+
const edges = graph.connections.flatMap((edge) => {
|
|
24
|
+
const source = ancestor(edge.source), target = ancestor(edge.target);
|
|
25
|
+
return source && target && source !== target
|
|
26
|
+
? [
|
|
27
|
+
{
|
|
28
|
+
...edge,
|
|
29
|
+
source,
|
|
30
|
+
target,
|
|
31
|
+
originalSource: edge.source,
|
|
32
|
+
originalTarget: edge.target,
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
: [];
|
|
36
|
+
});
|
|
37
|
+
return { nodes, edges };
|
|
38
|
+
}
|
|
39
|
+
export function relatedTests(graph, elementId) {
|
|
40
|
+
const descendants = new Set([elementId]);
|
|
41
|
+
let changed = true;
|
|
42
|
+
while (changed) {
|
|
43
|
+
changed = false;
|
|
44
|
+
for (const node of graph.elements)
|
|
45
|
+
if (node.parent &&
|
|
46
|
+
descendants.has(node.parent) &&
|
|
47
|
+
!descendants.has(node.id)) {
|
|
48
|
+
descendants.add(node.id);
|
|
49
|
+
changed = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// A suite attached to an interface or process is also useful inside its box.
|
|
53
|
+
// Inherit the nearest attachment, without claiming line or branch coverage.
|
|
54
|
+
const byId = new Map(graph.elements.map((node) => [node.id, node]));
|
|
55
|
+
let parent = byId.get(elementId)?.parent;
|
|
56
|
+
const visited = new Set();
|
|
57
|
+
while (parent && !visited.has(parent)) {
|
|
58
|
+
visited.add(parent);
|
|
59
|
+
if (graph.tests.some((test) => test.association === "attachment" && test.targets.includes(parent))) {
|
|
60
|
+
descendants.add(parent);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
parent = byId.get(parent)?.parent;
|
|
64
|
+
}
|
|
65
|
+
return graph.tests.filter((test) => test.targets.some((id) => descendants.has(id)));
|
|
66
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Isolated worker source, bundled with the desktop just like function benchmarks. */
|
|
2
|
+
export declare const operationBenchmarkWorker = "\nimport {writeFileSync} from 'node:fs';\nimport {pathToFileURL} from 'node:url';\nimport {createHash} from 'node:crypto';\nconst [file,report]=process.argv.slice(1);\nconst cancellation=new AbortController();\nprocess.on('SIGTERM',()=>cancellation.abort());\nconst bounded=(task,signal)=>new Promise((resolve,reject)=>{\n const aborted=()=>reject(Error(signal.reason?.name==='TimeoutError'?'Operation exceeded its time budget.':'Benchmark stopped.'));\n if(signal.aborted)return aborted();\n signal.addEventListener('abort',aborted,{once:true});\n Promise.resolve(task).then(resolve,reject).finally(()=>signal.removeEventListener('abort',aborted));\n});\ntry {\n const {default: plan}=await import(pathToFileURL(file).href);\n if(plan?.kind!=='operation'||typeof plan.name!=='string'||!plan.fixture?.name||!plan.fixture?.version||typeof plan.prepare!=='function'||typeof plan.run!=='function'||typeof plan.cleanup!=='function') throw Error('Export an operation benchmark with a name, versioned fixture, prepare, run and cleanup.');\n const count=plan.attempts??5;\n if(!Number.isSafeInteger(count)||count<1||count>10) throw Error('Choose between 1 and 10 product-operation attempts.');\n const timeout=Math.min(120000,Math.max(5000,plan.timeoutMs||120000));\n const values=[]; const phases=[]; let target;\n for(let attempt=0;attempt<count;attempt++) {\n if(cancellation.signal.aborted) throw Error('Benchmark stopped.');\n const signal=AbortSignal.any([cancellation.signal,AbortSignal.timeout(timeout)]);\n console.log('Preparing attempt '+(attempt+1)+'/'+count);\n const state=await bounded(plan.prepare(signal,attempt),signal);\n try {\n const start=performance.now();\n console.log('Measuring attempt '+(attempt+1)+'/'+count);\n const result=await bounded(plan.run(state,signal),signal);\n const elapsed=performance.now()-start;\n if(signal.aborted) throw Error('Operation did not complete within its measurement budget.');\n const measured=result?.target;\n if(!measured?.name||!measured.url||!measured.revision||!['client','server'].includes(measured.measurement)) throw Error('Identify the measured test environment, deployed revision and timing source.');\n const url=new URL(measured.url);\n if(url.protocol!=='https:'||url.username||url.password||url.search||url.hash) throw Error('Use the dedicated HTTPS test environment.');\n if(target&&JSON.stringify(target)!==JSON.stringify(measured)) throw Error('The target deployment changed during this run. Run again on one stable revision.');\n target=measured;\n const value=measured.measurement==='server'?result.durationMs:elapsed;\n if(!Number.isFinite(value)||value<0) throw Error('The operation did not return a valid measured duration.');\n values.push(value);\n if(result.phases) {\n if(Object.keys(result.phases).length>8||Object.values(result.phases).some(n=>!Number.isFinite(n)||n<0)||Object.values(result.phases).reduce((sum,n)=>sum+n,0)>value+Math.max(1,value*.01)) throw Error('Invalid operation phase durations.');\n phases.push(result.phases);\n }\n console.log('Attempt '+(attempt+1)+'/'+count+' completed');\n } finally { await bounded(plan.cleanup(state),AbortSignal.timeout(35000)); }\n }\n const mean=values.reduce((a,b)=>a+b,0)/values.length;\n const critical=[0,12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262][values.length-1]||0;\n const deviation=values.length>1?Math.sqrt(values.reduce((sum,value)=>sum+(value-mean)**2,0)/(values.length-1)):0;\n const sorted=[...values].sort((a,b)=>a-b);\n writeFileSync(report,JSON.stringify({kind:'operation',fixture:plan.fixture.name,fixtureVersion:plan.fixture.version,fixtureDescription:plan.fixture.condition,\n fixtureDigest:createHash('sha256').update(JSON.stringify(plan.fixture)).digest('hex'),target,\n runtime:Bun.version,cases:[{name:plan.name,samples:values.length,meanMs:mean,\n marginMs:values.length>1?critical*deviation/Math.sqrt(values.length):mean,\n p95Ms:sorted[Math.min(sorted.length-1,Math.ceil(sorted.length*.95)-1)],hz:mean>0?1000/mean:0,attemptsMs:values,attemptPhases:phases}]}));\n process.exit(0);\n} catch(error) { console.error(error instanceof Error?error.message:'Operation benchmark failed.');process.exit(1); }\n";
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Isolated worker source, bundled with the desktop just like function benchmarks. */
|
|
2
|
+
export const operationBenchmarkWorker = `
|
|
3
|
+
import {writeFileSync} from 'node:fs';
|
|
4
|
+
import {pathToFileURL} from 'node:url';
|
|
5
|
+
import {createHash} from 'node:crypto';
|
|
6
|
+
const [file,report]=process.argv.slice(1);
|
|
7
|
+
const cancellation=new AbortController();
|
|
8
|
+
process.on('SIGTERM',()=>cancellation.abort());
|
|
9
|
+
const bounded=(task,signal)=>new Promise((resolve,reject)=>{
|
|
10
|
+
const aborted=()=>reject(Error(signal.reason?.name==='TimeoutError'?'Operation exceeded its time budget.':'Benchmark stopped.'));
|
|
11
|
+
if(signal.aborted)return aborted();
|
|
12
|
+
signal.addEventListener('abort',aborted,{once:true});
|
|
13
|
+
Promise.resolve(task).then(resolve,reject).finally(()=>signal.removeEventListener('abort',aborted));
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
const {default: plan}=await import(pathToFileURL(file).href);
|
|
17
|
+
if(plan?.kind!=='operation'||typeof plan.name!=='string'||!plan.fixture?.name||!plan.fixture?.version||typeof plan.prepare!=='function'||typeof plan.run!=='function'||typeof plan.cleanup!=='function') throw Error('Export an operation benchmark with a name, versioned fixture, prepare, run and cleanup.');
|
|
18
|
+
const count=plan.attempts??5;
|
|
19
|
+
if(!Number.isSafeInteger(count)||count<1||count>10) throw Error('Choose between 1 and 10 product-operation attempts.');
|
|
20
|
+
const timeout=Math.min(120000,Math.max(5000,plan.timeoutMs||120000));
|
|
21
|
+
const values=[]; const phases=[]; let target;
|
|
22
|
+
for(let attempt=0;attempt<count;attempt++) {
|
|
23
|
+
if(cancellation.signal.aborted) throw Error('Benchmark stopped.');
|
|
24
|
+
const signal=AbortSignal.any([cancellation.signal,AbortSignal.timeout(timeout)]);
|
|
25
|
+
console.log('Preparing attempt '+(attempt+1)+'/'+count);
|
|
26
|
+
const state=await bounded(plan.prepare(signal,attempt),signal);
|
|
27
|
+
try {
|
|
28
|
+
const start=performance.now();
|
|
29
|
+
console.log('Measuring attempt '+(attempt+1)+'/'+count);
|
|
30
|
+
const result=await bounded(plan.run(state,signal),signal);
|
|
31
|
+
const elapsed=performance.now()-start;
|
|
32
|
+
if(signal.aborted) throw Error('Operation did not complete within its measurement budget.');
|
|
33
|
+
const measured=result?.target;
|
|
34
|
+
if(!measured?.name||!measured.url||!measured.revision||!['client','server'].includes(measured.measurement)) throw Error('Identify the measured test environment, deployed revision and timing source.');
|
|
35
|
+
const url=new URL(measured.url);
|
|
36
|
+
if(url.protocol!=='https:'||url.username||url.password||url.search||url.hash) throw Error('Use the dedicated HTTPS test environment.');
|
|
37
|
+
if(target&&JSON.stringify(target)!==JSON.stringify(measured)) throw Error('The target deployment changed during this run. Run again on one stable revision.');
|
|
38
|
+
target=measured;
|
|
39
|
+
const value=measured.measurement==='server'?result.durationMs:elapsed;
|
|
40
|
+
if(!Number.isFinite(value)||value<0) throw Error('The operation did not return a valid measured duration.');
|
|
41
|
+
values.push(value);
|
|
42
|
+
if(result.phases) {
|
|
43
|
+
if(Object.keys(result.phases).length>8||Object.values(result.phases).some(n=>!Number.isFinite(n)||n<0)||Object.values(result.phases).reduce((sum,n)=>sum+n,0)>value+Math.max(1,value*.01)) throw Error('Invalid operation phase durations.');
|
|
44
|
+
phases.push(result.phases);
|
|
45
|
+
}
|
|
46
|
+
console.log('Attempt '+(attempt+1)+'/'+count+' completed');
|
|
47
|
+
} finally { await bounded(plan.cleanup(state),AbortSignal.timeout(35000)); }
|
|
48
|
+
}
|
|
49
|
+
const mean=values.reduce((a,b)=>a+b,0)/values.length;
|
|
50
|
+
const critical=[0,12.706,4.303,3.182,2.776,2.571,2.447,2.365,2.306,2.262][values.length-1]||0;
|
|
51
|
+
const deviation=values.length>1?Math.sqrt(values.reduce((sum,value)=>sum+(value-mean)**2,0)/(values.length-1)):0;
|
|
52
|
+
const sorted=[...values].sort((a,b)=>a-b);
|
|
53
|
+
writeFileSync(report,JSON.stringify({kind:'operation',fixture:plan.fixture.name,fixtureVersion:plan.fixture.version,fixtureDescription:plan.fixture.condition,
|
|
54
|
+
fixtureDigest:createHash('sha256').update(JSON.stringify(plan.fixture)).digest('hex'),target,
|
|
55
|
+
runtime:Bun.version,cases:[{name:plan.name,samples:values.length,meanMs:mean,
|
|
56
|
+
marginMs:values.length>1?critical*deviation/Math.sqrt(values.length):mean,
|
|
57
|
+
p95Ms:sorted[Math.min(sorted.length-1,Math.ceil(sorted.length*.95)-1)],hz:mean>0?1000/mean:0,attemptsMs:values,attemptPhases:phases}]}));
|
|
58
|
+
process.exit(0);
|
|
59
|
+
} catch(error) { console.error(error instanceof Error?error.message:'Operation benchmark failed.');process.exit(1); }
|
|
60
|
+
`;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** An ordinary async product operation, with setup/cleanup outside its timing. */
|
|
2
|
+
export interface OperationBenchmark<State> {
|
|
3
|
+
kind: "operation";
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
startsWhen?: string;
|
|
7
|
+
endsWhen?: string;
|
|
8
|
+
fixture: {
|
|
9
|
+
name: string;
|
|
10
|
+
version: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
};
|
|
13
|
+
attempts?: number;
|
|
14
|
+
timeoutMs?: number;
|
|
15
|
+
prepare: (signal: AbortSignal, attempt: number) => Promise<State>;
|
|
16
|
+
run: (state: State, signal: AbortSignal) => Promise<{
|
|
17
|
+
/** Omit for client-observed wall time; supply only a measured server duration. */
|
|
18
|
+
durationMs?: number;
|
|
19
|
+
/** Measured, non-overlapping phases of this operation, in milliseconds. */
|
|
20
|
+
phases?: Record<string, number>;
|
|
21
|
+
target: {
|
|
22
|
+
name: string;
|
|
23
|
+
url: string;
|
|
24
|
+
revision: string;
|
|
25
|
+
measurement: "client" | "server";
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
cleanup: (state: State) => Promise<void>;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Aggregate OTel instruments. No invocation IDs, payloads or per-object retention. */
|
|
2
|
+
import type { Meter } from "@opentelemetry/api";
|
|
3
|
+
import type { FactoryEvent } from "./annotations.js";
|
|
4
|
+
export declare function factoryMetricRecorder(meter: Meter, environment?: string): (event: FactoryEvent) => void;
|
|
5
|
+
export interface OtlpMetricOptions {
|
|
6
|
+
intervalMs?: number;
|
|
7
|
+
service: string;
|
|
8
|
+
configuration: () => {
|
|
9
|
+
endpoint?: string;
|
|
10
|
+
headers?: string;
|
|
11
|
+
environment?: string;
|
|
12
|
+
};
|
|
13
|
+
waitUntil: (task: Promise<unknown>) => void;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
}
|
|
16
|
+
/** Lazy, bounded SDK export scheduled by the host's waitUntil, including Durable Objects.
|
|
17
|
+
* No global timers and no request waits. Missing configuration is a zero-network no-op. */
|
|
18
|
+
export declare function createOtlpMetrics(options: OtlpMetricOptions): {
|
|
19
|
+
emit: (event: FactoryEvent) => void;
|
|
20
|
+
flush: () => Promise<void>;
|
|
21
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { MeterProvider, MetricReader, AggregationType, } from "@opentelemetry/sdk-metrics";
|
|
2
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
3
|
+
import { JsonMetricsSerializer } from "@opentelemetry/otlp-transformer";
|
|
4
|
+
export function factoryMetricRecorder(meter, environment = "production") {
|
|
5
|
+
const calls = meter.createCounter("fractory.calls", {
|
|
6
|
+
unit: "{call}",
|
|
7
|
+
description: "Completed boundary invocations, including failures",
|
|
8
|
+
});
|
|
9
|
+
const duration = meter.createHistogram("fractory.duration", {
|
|
10
|
+
unit: "s",
|
|
11
|
+
description: "Boundary wall time",
|
|
12
|
+
});
|
|
13
|
+
return (event) => {
|
|
14
|
+
if (event.status === "started" || !event.targetId)
|
|
15
|
+
return;
|
|
16
|
+
const attributes = {
|
|
17
|
+
"fractory.target": event.targetId,
|
|
18
|
+
"fractory.caller": event.callerId || "external",
|
|
19
|
+
"fractory.environment": environment,
|
|
20
|
+
"fractory.outcome": event.status === "failed" ? "error" : "ok",
|
|
21
|
+
};
|
|
22
|
+
calls.add(1, attributes);
|
|
23
|
+
if (event.durationMs !== undefined &&
|
|
24
|
+
Number.isFinite(event.durationMs) &&
|
|
25
|
+
event.durationMs >= 0)
|
|
26
|
+
duration.record(event.durationMs / 1000, attributes);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
class FlushReader extends MetricReader {
|
|
30
|
+
send;
|
|
31
|
+
constructor(send) {
|
|
32
|
+
super({ cardinalitySelector: () => 1000 });
|
|
33
|
+
this.send = send;
|
|
34
|
+
}
|
|
35
|
+
async onForceFlush() {
|
|
36
|
+
const { resourceMetrics } = await this.collect();
|
|
37
|
+
await this.send(resourceMetrics);
|
|
38
|
+
}
|
|
39
|
+
async onShutdown() { }
|
|
40
|
+
}
|
|
41
|
+
/** Lazy, bounded SDK export scheduled by the host's waitUntil, including Durable Objects.
|
|
42
|
+
* No global timers and no request waits. Missing configuration is a zero-network no-op. */
|
|
43
|
+
export function createOtlpMetrics(options) {
|
|
44
|
+
let provider, record;
|
|
45
|
+
let pending, dirty = false;
|
|
46
|
+
const flush = () => provider?.forceFlush({ timeoutMillis: 8000 }) || Promise.resolve();
|
|
47
|
+
const emit = (event) => {
|
|
48
|
+
if (event.status === "started")
|
|
49
|
+
return;
|
|
50
|
+
try {
|
|
51
|
+
if (!provider) {
|
|
52
|
+
const config = options.configuration();
|
|
53
|
+
if (!config.endpoint)
|
|
54
|
+
return;
|
|
55
|
+
const endpoint = new URL(config.endpoint);
|
|
56
|
+
if (endpoint.username ||
|
|
57
|
+
endpoint.password ||
|
|
58
|
+
(endpoint.protocol !== "https:" &&
|
|
59
|
+
!(endpoint.protocol === "http:" &&
|
|
60
|
+
["127.0.0.1", "localhost", "[::1]"].includes(endpoint.hostname))))
|
|
61
|
+
return;
|
|
62
|
+
const headers = {
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
};
|
|
65
|
+
for (const pair of (config.headers || "").split(",").filter(Boolean)) {
|
|
66
|
+
const equal = pair.indexOf("=");
|
|
67
|
+
if (equal <= 0)
|
|
68
|
+
continue;
|
|
69
|
+
headers[pair.slice(0, equal).trim()] = decodeURIComponent(pair.slice(equal + 1).trim());
|
|
70
|
+
}
|
|
71
|
+
const reader = new FlushReader(async (metrics) => {
|
|
72
|
+
if (!metrics.scopeMetrics.some((scope) => scope.metrics.length))
|
|
73
|
+
return;
|
|
74
|
+
const body = JsonMetricsSerializer.serializeRequest(metrics);
|
|
75
|
+
if (!body || body.byteLength > 2 * 1024 * 1024)
|
|
76
|
+
return;
|
|
77
|
+
const response = await (options.fetch || fetch)(endpoint, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers,
|
|
80
|
+
body: body,
|
|
81
|
+
redirect: "error",
|
|
82
|
+
signal: AbortSignal.timeout(6000),
|
|
83
|
+
});
|
|
84
|
+
if (!response.ok)
|
|
85
|
+
throw Error("Metric export failed");
|
|
86
|
+
});
|
|
87
|
+
provider = new MeterProvider({
|
|
88
|
+
resource: resourceFromAttributes({
|
|
89
|
+
"service.name": options.service,
|
|
90
|
+
"service.instance.id": crypto.randomUUID(),
|
|
91
|
+
...(event.codeRevision
|
|
92
|
+
? { "service.version": event.codeRevision }
|
|
93
|
+
: {}),
|
|
94
|
+
"deployment.environment.name": config.environment || "production",
|
|
95
|
+
}),
|
|
96
|
+
readers: [reader],
|
|
97
|
+
views: [
|
|
98
|
+
{
|
|
99
|
+
instrumentName: "fractory.duration",
|
|
100
|
+
aggregation: {
|
|
101
|
+
type: AggregationType.EXPLICIT_BUCKET_HISTOGRAM,
|
|
102
|
+
options: {
|
|
103
|
+
boundaries: [
|
|
104
|
+
0.00001, 0.00005, 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.025,
|
|
105
|
+
0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 30, 60, 300, 900, 3600,
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
});
|
|
112
|
+
record = factoryMetricRecorder(provider.getMeter("fractory", "1"), config.environment || "production");
|
|
113
|
+
}
|
|
114
|
+
record(event);
|
|
115
|
+
dirty = true;
|
|
116
|
+
if (!pending) {
|
|
117
|
+
pending = (async () => {
|
|
118
|
+
await new Promise((resolve) => setTimeout(resolve, Math.max(100, Math.min(10000, options.intervalMs || 5000))));
|
|
119
|
+
for (let cycle = 0; dirty && cycle < 4; cycle++) {
|
|
120
|
+
dirty = false;
|
|
121
|
+
try {
|
|
122
|
+
await flush();
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
/* cumulative SDK state survives for the next flush */
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
})().finally(() => {
|
|
129
|
+
pending = undefined;
|
|
130
|
+
});
|
|
131
|
+
options.waitUntil(pending);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
/* instrumentation is observational */
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return {
|
|
139
|
+
emit,
|
|
140
|
+
flush: async () => {
|
|
141
|
+
if (pending)
|
|
142
|
+
await pending;
|
|
143
|
+
await flush();
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { DefinitionGraph } from "./model.js";
|
|
2
|
+
import type { ActivityCell } from "./map-activity.js";
|
|
3
|
+
import type { TimeWindow } from "./time-window.js";
|
|
4
|
+
export interface MetricBoundary {
|
|
5
|
+
target: string;
|
|
6
|
+
caller?: string;
|
|
7
|
+
calls: number;
|
|
8
|
+
callsKnown?: boolean;
|
|
9
|
+
errors: number;
|
|
10
|
+
buckets: {
|
|
11
|
+
le: number;
|
|
12
|
+
count: number;
|
|
13
|
+
}[];
|
|
14
|
+
trend: {
|
|
15
|
+
at: number;
|
|
16
|
+
value: number;
|
|
17
|
+
}[];
|
|
18
|
+
failedTrend?: {
|
|
19
|
+
at: number;
|
|
20
|
+
value: number;
|
|
21
|
+
}[];
|
|
22
|
+
latencyTrend?: {
|
|
23
|
+
at: number;
|
|
24
|
+
buckets: {
|
|
25
|
+
le: number;
|
|
26
|
+
count: number;
|
|
27
|
+
}[];
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
export interface MetricGauge {
|
|
31
|
+
id: string;
|
|
32
|
+
label: string;
|
|
33
|
+
unit: string;
|
|
34
|
+
aggregation: "sum" | "max";
|
|
35
|
+
description?: string;
|
|
36
|
+
chart?: "line" | "bar";
|
|
37
|
+
sources?: {
|
|
38
|
+
block: string;
|
|
39
|
+
query: string;
|
|
40
|
+
}[];
|
|
41
|
+
status?: "ready" | "empty" | "error";
|
|
42
|
+
error?: string;
|
|
43
|
+
values: {
|
|
44
|
+
block: string;
|
|
45
|
+
value: number;
|
|
46
|
+
trend: {
|
|
47
|
+
at: number;
|
|
48
|
+
value: number;
|
|
49
|
+
}[];
|
|
50
|
+
}[];
|
|
51
|
+
}
|
|
52
|
+
export interface RuntimeMetrics {
|
|
53
|
+
source: "prometheus";
|
|
54
|
+
configured: boolean;
|
|
55
|
+
window: TimeWindow;
|
|
56
|
+
environment: string;
|
|
57
|
+
checkedAt: string;
|
|
58
|
+
lastSampleAt?: string;
|
|
59
|
+
boundaries: MetricBoundary[];
|
|
60
|
+
gauges: MetricGauge[];
|
|
61
|
+
warnings: string[];
|
|
62
|
+
}
|
|
63
|
+
export interface BlockMetric {
|
|
64
|
+
callsKnown?: boolean;
|
|
65
|
+
failedTrend?: {
|
|
66
|
+
at: number;
|
|
67
|
+
value: number;
|
|
68
|
+
}[];
|
|
69
|
+
latencyTrend?: {
|
|
70
|
+
at: number;
|
|
71
|
+
value: number;
|
|
72
|
+
}[];
|
|
73
|
+
calls: number;
|
|
74
|
+
errors: number;
|
|
75
|
+
errorRate: number | null;
|
|
76
|
+
p95Ms: number | null;
|
|
77
|
+
buckets: {
|
|
78
|
+
le: number;
|
|
79
|
+
count: number;
|
|
80
|
+
}[];
|
|
81
|
+
trend: {
|
|
82
|
+
at: number;
|
|
83
|
+
value: number;
|
|
84
|
+
}[];
|
|
85
|
+
}
|
|
86
|
+
export declare function histogramPercentile(buckets: {
|
|
87
|
+
le: number;
|
|
88
|
+
count: number;
|
|
89
|
+
}[], q?: number): number | null;
|
|
90
|
+
export declare function metricRollup(graph: DefinitionGraph, source: RuntimeMetrics): {
|
|
91
|
+
blocks: Record<string, BlockMetric>;
|
|
92
|
+
links: Record<string, {
|
|
93
|
+
count: number;
|
|
94
|
+
label: string;
|
|
95
|
+
}>;
|
|
96
|
+
gauges: Record<string, Record<string, {
|
|
97
|
+
value: number;
|
|
98
|
+
trend: {
|
|
99
|
+
at: number;
|
|
100
|
+
value: number;
|
|
101
|
+
}[];
|
|
102
|
+
}>>;
|
|
103
|
+
unmapped: number;
|
|
104
|
+
};
|
|
105
|
+
export declare function formatNumber(value: number): string;
|
|
106
|
+
export declare function durationLabel(ms: number): string;
|
|
107
|
+
export declare function metricCells(graph: DefinitionGraph, source: RuntimeMetrics, metric: string): {
|
|
108
|
+
blocks: Record<string, BlockMetric>;
|
|
109
|
+
links: Record<string, {
|
|
110
|
+
count: number;
|
|
111
|
+
label: string;
|
|
112
|
+
}>;
|
|
113
|
+
gauges: Record<string, Record<string, {
|
|
114
|
+
value: number;
|
|
115
|
+
trend: {
|
|
116
|
+
at: number;
|
|
117
|
+
value: number;
|
|
118
|
+
}[];
|
|
119
|
+
}>>;
|
|
120
|
+
unmapped: number;
|
|
121
|
+
cells: Record<string, ActivityCell>;
|
|
122
|
+
};
|
|
123
|
+
export interface BenchmarkCase {
|
|
124
|
+
name: string;
|
|
125
|
+
samples: number;
|
|
126
|
+
meanMs: number;
|
|
127
|
+
marginMs: number;
|
|
128
|
+
p95Ms: number;
|
|
129
|
+
hz: number;
|
|
130
|
+
attemptsMs?: number[];
|
|
131
|
+
attemptPhases?: Record<string, number>[];
|
|
132
|
+
}
|
|
133
|
+
export interface BenchmarkRun {
|
|
134
|
+
runnerPid?: number;
|
|
135
|
+
heartbeatAt?: number;
|
|
136
|
+
kind?: "function" | "operation";
|
|
137
|
+
fixture?: string;
|
|
138
|
+
fixtureVersion?: string;
|
|
139
|
+
fixtureDescription?: string;
|
|
140
|
+
target?: {
|
|
141
|
+
name: string;
|
|
142
|
+
url: string;
|
|
143
|
+
revision: string;
|
|
144
|
+
measurement: "client" | "server";
|
|
145
|
+
};
|
|
146
|
+
id: string;
|
|
147
|
+
file: string;
|
|
148
|
+
blockIds: string[];
|
|
149
|
+
at: string;
|
|
150
|
+
status: "queued" | "running" | "passed" | "failed";
|
|
151
|
+
commit: string | null;
|
|
152
|
+
baseCommit: string;
|
|
153
|
+
codeDigest: string;
|
|
154
|
+
scenario: string;
|
|
155
|
+
environment: string;
|
|
156
|
+
machine: string;
|
|
157
|
+
cases: BenchmarkCase[];
|
|
158
|
+
output: string;
|
|
159
|
+
error?: string;
|
|
160
|
+
durationMs?: number;
|
|
161
|
+
}
|
|
162
|
+
export interface BenchmarkView {
|
|
163
|
+
plans: {
|
|
164
|
+
file: string;
|
|
165
|
+
blocks: string[];
|
|
166
|
+
label: string;
|
|
167
|
+
kind?: "function" | "operation";
|
|
168
|
+
fixture?: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
startsWhen?: string;
|
|
171
|
+
endsWhen?: string;
|
|
172
|
+
attempts?: number;
|
|
173
|
+
}[];
|
|
174
|
+
runs: BenchmarkRun[];
|
|
175
|
+
baselines: Record<string, string>;
|
|
176
|
+
}
|
|
177
|
+
/** A reason is preferable to silently comparing unrelated workloads or a run with itself. */
|
|
178
|
+
export declare function benchmarkComparisonReason(current: BenchmarkRun, baseline: BenchmarkRun | undefined, name: string): string | undefined;
|
|
179
|
+
export declare function benchmarkReference(view: BenchmarkView, current: BenchmarkRun): BenchmarkRun | undefined;
|
|
180
|
+
export declare function compareBenchmark(current: BenchmarkRun, baseline: BenchmarkRun | undefined, name: string): {
|
|
181
|
+
readonly percent: number;
|
|
182
|
+
readonly significant: boolean;
|
|
183
|
+
readonly direction: "slower" | "faster" | "similar";
|
|
184
|
+
} | null;
|
|
185
|
+
export declare function benchmarkCells(graph: DefinitionGraph, view: BenchmarkView): Record<string, ActivityCell>;
|