afyx-engineering-kit 0.0.0-stage → 0.1.0-alpha.3
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/.afyx-source-revision +1 -0
- package/LICENSE +21 -0
- package/README.md +377 -2
- package/SECURITY.md +74 -0
- package/afyx-context/LICENSE +21 -0
- package/afyx-context/README.md +155 -0
- package/afyx-context/afyx-context.json +30 -0
- package/afyx-context/contracts/integration-v1.schema.json +34 -0
- package/afyx-context/package-lock.json +53 -0
- package/afyx-context/package.json +34 -0
- package/afyx-context/scripts/benchmark.mjs +39 -0
- package/afyx-context/scripts/build.mjs +15 -0
- package/afyx-context/scripts/comparative-benchmark.mjs +342 -0
- package/afyx-context/scripts/comparative-worker.mjs +74 -0
- package/afyx-context/scripts/graph-integration-e2e.mjs +188 -0
- package/afyx-context/scripts/integrated-dogfood.mjs +309 -0
- package/afyx-context/src/budget.js +166 -0
- package/afyx-context/src/cli.js +110 -0
- package/afyx-context/src/coordination.js +343 -0
- package/afyx-context/src/engine.js +198 -0
- package/afyx-context/src/errors.js +14 -0
- package/afyx-context/src/graph-integration-worker.js +70 -0
- package/afyx-context/src/graph-integration.js +373 -0
- package/afyx-context/src/graph-mcp-bridge.js +103 -0
- package/afyx-context/src/index.js +25 -0
- package/afyx-context/src/integrations.js +87 -0
- package/afyx-context/src/memory.js +255 -0
- package/afyx-context/src/storage.js +364 -0
- package/afyx-context/test-fixtures/coordination-worker.mjs +52 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__init__.py +1 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/__manifest__.py +4 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/__init__.py +1 -0
- package/afyx-context/test-fixtures/graph-consumer-repo/addons/sale_extension/models/sale_order.py +5 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__init__.py +1 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/__manifest__.py +10 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/__init__.py +2 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order.py +20 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/models/sale_order_audit.py +11 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/security/ir.model.access.csv +2 -0
- package/afyx-context/test-fixtures/integrated-dogfood-repo/addons/integrated_sales/views/sale_order_views.xml +14 -0
- package/afyx-forge/LICENSE +55 -0
- package/afyx-forge/README.md +126 -0
- package/afyx-forge/afyx-forge.json +28 -0
- package/afyx-forge/bin/afyx-forge +4 -0
- package/afyx-forge/bin/afyx-forge.cmd +3 -0
- package/afyx-forge/bin/afyx-forge.js +16 -0
- package/afyx-forge/contracts/forge-plan-v1.schema.json +172 -0
- package/afyx-forge/package.json +26 -0
- package/afyx-forge/src/classifier.js +190 -0
- package/afyx-forge/src/cli.js +111 -0
- package/afyx-forge/src/doctor.js +105 -0
- package/afyx-forge/src/guidance.js +120 -0
- package/afyx-forge/src/index.js +273 -0
- package/afyx-forge/src/planning.js +107 -0
- package/afyx-forge/src/policy.js +109 -0
- package/afyx-forge/src/workflow-refiner.js +151 -0
- package/afyx-graph/afyx-graph.json +20 -0
- package/afyx-graph/engine/LICENSE +21 -0
- package/afyx-graph/engine/README.md +104 -0
- package/afyx-graph/engine/release/RELEASE-MANIFEST.json +21 -0
- package/afyx-graph/engine/release/SHA256SUMS +2 -0
- package/afyx-graph/engine/release/afyx-graph-linux-x64.tar.gz +0 -0
- package/afyx-graph/engine/release/afyx-graph-win32-x64.zip +0 -0
- package/afyx-graph/engine/scripts/distribution-contract.mjs +212 -0
- package/afyx-graph/engine/scripts/distribution-product.json +33 -0
- package/bin/afyx-engineering-kit.mjs +61 -0
- package/install.ps1 +1053 -0
- package/install.sh +617 -0
- package/package.json +66 -4
- package/scripts/afyx-capability-orchestrator.mjs +752 -0
- package/scripts/afyx-claude-integration.mjs +547 -0
- package/scripts/afyx-context-artifact.mjs +105 -0
- package/scripts/afyx-credential-broker.mjs +75 -0
- package/scripts/afyx-doctor.ps1 +152 -0
- package/scripts/afyx-doctor.sh +146 -0
- package/scripts/afyx-forge-artifact.mjs +183 -0
- package/scripts/afyx-global-routing-policy.md +12 -0
- package/scripts/afyx-global-routing.mjs +168 -0
- package/scripts/afyx-graph-artifact.mjs +178 -0
- package/scripts/afyx-host-adapters.mjs +543 -0
- package/scripts/afyx-host-bridge-lifecycle.mjs +174 -0
- package/scripts/afyx-host-bridge.mjs +288 -0
- package/scripts/afyx-integration-contracts.mjs +825 -0
- package/scripts/afyx-mcp-integration.mjs +528 -0
- package/scripts/afyx-modular-integration.mjs +361 -0
- package/scripts/afyx-modular-runtime.mjs +451 -0
- package/scripts/afyx-native-skill-host.mjs +124 -0
- package/scripts/afyx-npm-installer.mjs +486 -0
- package/scripts/afyx-project.ps1 +205 -0
- package/scripts/afyx-project.sh +207 -0
- package/scripts/afyx-provider-backup.mjs +1206 -0
- package/scripts/afyx-provider-integration.mjs +724 -0
- package/scripts/afyx-provider-inventory.mjs +147 -0
- package/scripts/afyx-security-auditor.mjs +224 -0
- package/scripts/afyx-skill-engineering.mjs +354 -0
- package/scripts/afyx-tool-family-routing.mjs +64 -0
- package/scripts/afyx-universal-runtime.mjs +530 -0
- package/scripts/alpha_acceptance_preflight.py +240 -0
- package/scripts/benchmark-graph-memory.mjs +96 -0
- package/scripts/benchmark_capability_orchestrator.mjs +64 -0
- package/scripts/build-windows-installer.ps1 +259 -0
- package/scripts/build_forge_synthetic_image.py +328 -0
- package/scripts/check-reference-staleness.py +71 -0
- package/scripts/components.json +254 -0
- package/scripts/contracts/afyx-capability-request-v1.schema.json +189 -0
- package/scripts/contracts/afyx-capability-result-v1.schema.json +32 -0
- package/scripts/dogfood_engineering_comparison.mjs +303 -0
- package/scripts/engineering-assurance.json +28 -0
- package/scripts/install-afyx-context.ps1 +142 -0
- package/scripts/install-afyx-context.sh +126 -0
- package/scripts/install-afyx-forge.ps1 +265 -0
- package/scripts/install-afyx-forge.sh +273 -0
- package/scripts/install-afyx-graph.ps1 +571 -0
- package/scripts/install-afyx-graph.sh +438 -0
- package/scripts/install-codex-usage-tracker.ps1 +172 -0
- package/scripts/lib/AfyxComponents.psm1 +399 -0
- package/scripts/lib/AfyxSkillLifecycle.psm1 +289 -0
- package/scripts/lib/AfyxTerminal.psm1 +838 -0
- package/scripts/lib/afyx-components.sh +256 -0
- package/scripts/lib/afyx-skill-lifecycle.sh +271 -0
- package/scripts/link-global-dev.ps1 +193 -0
- package/scripts/link-global-dev.sh +130 -0
- package/scripts/phase8-paired-evidence.mjs +195 -0
- package/scripts/phase8-representative-workload.mjs +771 -0
- package/scripts/phase8-session-recorder.mjs +157 -0
- package/scripts/phase8_event_ledger.py +248 -0
- package/scripts/phase8_evidence_discovery.py +189 -0
- package/scripts/prepare-g6-package.mjs +349 -0
- package/scripts/resolve-git-release-artifacts.mjs +321 -0
- package/scripts/stage-npm-release.mjs +94 -0
- package/scripts/validate-afyx-graph.py +203 -0
- package/scripts/validate-components.py +194 -0
- package/scripts/validate-engineering-assurance.py +281 -0
- package/scripts/verify-graph-archive.mjs +64 -0
- package/skills/afyx-context/SKILL.md +26 -0
- package/skills/afyx-engineering-expert/README.md +42 -0
- package/skills/afyx-engineering-expert/SKILL.md +70 -0
- package/skills/afyx-engineering-expert/assets/result-template.md +15 -0
- package/skills/afyx-engineering-expert/references/ai-ml-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/business-analyst.md +17 -0
- package/skills/afyx-engineering-expert/references/clean-code-engineer.md +26 -0
- package/skills/afyx-engineering-expert/references/code-reviewer.md +24 -0
- package/skills/afyx-engineering-expert/references/cybersecurity-devsecops.md +17 -0
- package/skills/afyx-engineering-expert/references/data-analyst-bi.md +24 -0
- package/skills/afyx-engineering-expert/references/data-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/database-administrator.md +17 -0
- package/skills/afyx-engineering-expert/references/debugging-specialist.md +24 -0
- package/skills/afyx-engineering-expert/references/embedded-iot-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/erp-technical-specialist.md +17 -0
- package/skills/afyx-engineering-expert/references/hardware-diagnostics-auditor.md +24 -0
- package/skills/afyx-engineering-expert/references/hardware-electronics-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/integration-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/legacy-modernization-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/llmops-prompt-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/network-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/performance-benchmark-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/platform-engineer.md +24 -0
- package/skills/afyx-engineering-expert/references/product-manager.md +17 -0
- package/skills/afyx-engineering-expert/references/qa-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/site-reliability-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/software-engineer.md +17 -0
- package/skills/afyx-engineering-expert/references/solutions-architect.md +17 -0
- package/skills/afyx-engineering-expert/references/specialists-index.md +33 -0
- package/skills/afyx-engineering-expert/references/subject-matter-expert.md +17 -0
- package/skills/afyx-engineering-expert/references/system-analyst.md +17 -0
- package/skills/afyx-engineering-expert/references/technical-project-manager.md +24 -0
- package/skills/afyx-engineering-expert/references/technical-writer.md +24 -0
- package/skills/afyx-engineering-expert/references/ui-ux-designer.md +17 -0
- package/skills/afyx-engineering-expert/workflows/ai-data-erp.md +20 -0
- package/skills/afyx-engineering-expert/workflows/debugging.md +10 -0
- package/skills/afyx-engineering-expert/workflows/discovery-design.md +11 -0
- package/skills/afyx-engineering-expert/workflows/implementation.md +12 -0
- package/skills/afyx-engineering-expert/workflows/incident-reliability.md +12 -0
- package/skills/afyx-engineering-expert/workflows/review-audit.md +13 -0
- package/skills/afyx-forge/SKILL.md +43 -0
- package/skills/afyx-forge/references/adaptive-policy.md +19 -0
- package/skills/efficient-coding/SKILL.md +33 -0
- package/skills/efficient-coding/references/investigation.md +27 -0
- package/skills/efficient-coding/references/token-efficiency.md +25 -0
- package/skills/efficient-coding/references/tool-routing.md +13 -0
- package/skills/odoo-engineering/SKILL.md +33 -0
- package/skills/odoo-engineering/references/common.md +9 -0
- package/skills/odoo-engineering/references/odoo-10.md +32 -0
- package/skills/odoo-engineering/references/odoo-11.md +26 -0
- package/skills/odoo-engineering/references/odoo-12.md +31 -0
- package/skills/odoo-engineering/references/odoo-13.md +27 -0
- package/skills/odoo-engineering/references/odoo-14.md +31 -0
- package/skills/odoo-engineering/references/odoo-15.md +34 -0
- package/skills/odoo-engineering/references/odoo-16.md +37 -0
- package/skills/odoo-engineering/references/odoo-17.md +37 -0
- package/skills/odoo-engineering/references/odoo-18.md +48 -0
- package/skills/odoo-engineering/references/odoo-19.md +43 -0
- package/skills/odoo-engineering/references/odoo-20.md +39 -0
- package/skills/odoo-engineering/references/reference-schema.md +16 -0
- package/skills/odoo-engineering/references/version-detection.md +13 -0
- package/tools/codex-usage/CodexUsage.psm1 +496 -0
- package/tools/codex-usage/codex-usage-doctor.ps1 +150 -0
- package/tools/codex-usage/codex-usage-pricing.json +25 -0
- package/tools/codex-usage/codex-usage-stop.ps1 +167 -0
- package/tools/codex-usage/codex-usage-watch.ps1 +250 -0
- package/tools/codex-usage/vscode-user-task.json +31 -0
- package/tools/windows-setup/SetupBootstrapper.cs +258 -0
- package/uninstall.ps1 +189 -0
- package/uninstall.sh +167 -0
- package/update.ps1 +95 -0
- package/update.sh +67 -0
- package/verify.ps1 +411 -0
- package/verify.sh +265 -0
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import crypto from 'node:crypto';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import process from 'node:process';
|
|
7
|
+
import { performance } from 'node:perf_hooks';
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
9
|
+
import { createRequire } from 'node:module';
|
|
10
|
+
|
|
11
|
+
// Paths
|
|
12
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const repositoryRoot = path.resolve(__dirname, '..');
|
|
14
|
+
const graphDist = path.join(repositoryRoot, 'afyx-graph', 'engine', 'dist');
|
|
15
|
+
const contextPkg = path.join(repositoryRoot, 'afyx-context', 'package.json');
|
|
16
|
+
const contextSrc = path.join(repositoryRoot, 'afyx-context', 'src', 'index.js');
|
|
17
|
+
|
|
18
|
+
// Dynamically resolve js-tiktoken portably across all platforms
|
|
19
|
+
const requireFromContext = createRequire(contextPkg);
|
|
20
|
+
let getEncoding;
|
|
21
|
+
try {
|
|
22
|
+
({ getEncoding } = await import('js-tiktoken'));
|
|
23
|
+
} catch {
|
|
24
|
+
const tiktokenPath = requireFromContext.resolve('js-tiktoken');
|
|
25
|
+
const mod = await import(pathToFileURL(tiktokenPath).href);
|
|
26
|
+
getEncoding = mod.getEncoding || mod.default?.getEncoding;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const encoder = getEncoding('o200k_base');
|
|
30
|
+
const sha256 = (val) => crypto.createHash('sha256').update(val).digest('hex');
|
|
31
|
+
const countTokens = (val) => encoder.encode(typeof val === 'string' ? val : JSON.stringify(val)).length;
|
|
32
|
+
|
|
33
|
+
function parseArgs() {
|
|
34
|
+
const args = process.argv.slice(2);
|
|
35
|
+
const options = {
|
|
36
|
+
ci: args.includes('--ci'),
|
|
37
|
+
writeEvidence: args.includes('--write-evidence'),
|
|
38
|
+
output: null,
|
|
39
|
+
injectFailure: null, // used for negative regression testing: e.g. 'corrupt-recovery', 'bypass-fail'
|
|
40
|
+
};
|
|
41
|
+
const outIdx = args.indexOf('--output');
|
|
42
|
+
if (outIdx !== -1 && args[outIdx + 1]) {
|
|
43
|
+
options.output = path.resolve(args[outIdx + 1]);
|
|
44
|
+
}
|
|
45
|
+
const failIdx = args.indexOf('--inject-failure');
|
|
46
|
+
if (failIdx !== -1 && args[failIdx + 1]) {
|
|
47
|
+
options.injectFailure = args[failIdx + 1];
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function measured(fn) {
|
|
53
|
+
const start = performance.now();
|
|
54
|
+
const val = await fn();
|
|
55
|
+
const durationMs = Number((performance.now() - start).toFixed(3));
|
|
56
|
+
return { val, durationMs };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function textOf(toolResult) {
|
|
60
|
+
if (!toolResult) return '';
|
|
61
|
+
if (typeof toolResult === 'string') return toolResult;
|
|
62
|
+
if (toolResult.content && Array.isArray(toolResult.content)) {
|
|
63
|
+
return toolResult.content.map((c) => c.text || '').join('\n');
|
|
64
|
+
}
|
|
65
|
+
return JSON.stringify(toolResult);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function fingerprintTree(dir) {
|
|
69
|
+
const files = [];
|
|
70
|
+
const walk = (cur) => {
|
|
71
|
+
for (const ent of fs.readdirSync(cur, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
72
|
+
const p = path.join(cur, ent.name);
|
|
73
|
+
if (ent.isDirectory()) walk(p);
|
|
74
|
+
else if (ent.isFile()) files.push(path.relative(dir, p).replaceAll('\\', '/'));
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
walk(dir);
|
|
78
|
+
const hash = sha256(files.map((f) => `${f}\0${sha256(fs.readFileSync(path.join(dir, f)))}`).join('\n'));
|
|
79
|
+
return { files, sha256: hash };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function createRepresentativeFixture(baseDir) {
|
|
83
|
+
const repoDir = path.join(baseDir, 'representative-repo');
|
|
84
|
+
fs.mkdirSync(repoDir, { recursive: true });
|
|
85
|
+
|
|
86
|
+
// 1. Module: base_accounting
|
|
87
|
+
const modAcc = path.join(repoDir, 'addons', 'base_accounting');
|
|
88
|
+
fs.mkdirSync(path.join(modAcc, 'models'), { recursive: true });
|
|
89
|
+
fs.mkdirSync(path.join(modAcc, 'tests'), { recursive: true });
|
|
90
|
+
fs.mkdirSync(path.join(modAcc, 'security'), { recursive: true });
|
|
91
|
+
|
|
92
|
+
fs.writeFileSync(path.join(modAcc, '__manifest__.py'), `
|
|
93
|
+
{
|
|
94
|
+
'name': 'Base Accounting',
|
|
95
|
+
'version': '1.0.0',
|
|
96
|
+
'category': 'Accounting',
|
|
97
|
+
'depends': ['base'],
|
|
98
|
+
'data': ['security/ir.model.access.csv'],
|
|
99
|
+
'installable': True,
|
|
100
|
+
}
|
|
101
|
+
`.trim());
|
|
102
|
+
|
|
103
|
+
fs.writeFileSync(path.join(modAcc, 'models', '__init__.py'), `from . import account_move\n`);
|
|
104
|
+
|
|
105
|
+
fs.writeFileSync(path.join(modAcc, 'models', 'account_move.py'), `
|
|
106
|
+
from odoo import fields, models, api
|
|
107
|
+
|
|
108
|
+
class AccountMove(models.Model):
|
|
109
|
+
_name = "account.move"
|
|
110
|
+
_description = "Journal Entry"
|
|
111
|
+
|
|
112
|
+
name = fields.Char(string="Number", required=True, copy=False, default="/")
|
|
113
|
+
state = fields.Selection([('draft', 'Draft'), ('posted', 'Posted')], default='draft')
|
|
114
|
+
amount_total = fields.Monetary(string="Total")
|
|
115
|
+
|
|
116
|
+
def action_post(self):
|
|
117
|
+
for move in self:
|
|
118
|
+
move.state = 'posted'
|
|
119
|
+
return True
|
|
120
|
+
`.trim());
|
|
121
|
+
|
|
122
|
+
fs.writeFileSync(path.join(modAcc, 'security', 'ir.model.access.csv'), `
|
|
123
|
+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
|
124
|
+
access_account_move,account.move,model_account_move,base.group_user,1,1,1,1
|
|
125
|
+
`.trim());
|
|
126
|
+
|
|
127
|
+
fs.writeFileSync(path.join(modAcc, 'tests', '__init__.py'), `from . import test_account_move\n`);
|
|
128
|
+
fs.writeFileSync(path.join(modAcc, 'tests', 'test_account_move.py'), `
|
|
129
|
+
import unittest
|
|
130
|
+
from odoo.tests.common import TransactionCase
|
|
131
|
+
|
|
132
|
+
class TestAccountMove(TransactionCase):
|
|
133
|
+
def test_post_flow(self):
|
|
134
|
+
move = self.env['account.move'].create({'name': 'INV/001'})
|
|
135
|
+
move.action_post()
|
|
136
|
+
self.assertEqual(move.state, 'posted')
|
|
137
|
+
`.trim());
|
|
138
|
+
|
|
139
|
+
// 2. Module: sale_enterprise
|
|
140
|
+
const modSale = path.join(repoDir, 'addons', 'sale_enterprise');
|
|
141
|
+
fs.mkdirSync(path.join(modSale, 'models'), { recursive: true });
|
|
142
|
+
fs.mkdirSync(path.join(modSale, 'views'), { recursive: true });
|
|
143
|
+
fs.mkdirSync(path.join(modSale, 'tests'), { recursive: true });
|
|
144
|
+
fs.mkdirSync(path.join(modSale, 'security'), { recursive: true });
|
|
145
|
+
|
|
146
|
+
fs.writeFileSync(path.join(modSale, '__manifest__.py'), `
|
|
147
|
+
{
|
|
148
|
+
'name': 'Sale Enterprise Integration',
|
|
149
|
+
'version': '1.0.0',
|
|
150
|
+
'depends': ['base_accounting'],
|
|
151
|
+
'data': [
|
|
152
|
+
'security/ir.model.access.csv',
|
|
153
|
+
'views/sale_order_views.xml',
|
|
154
|
+
],
|
|
155
|
+
'installable': True,
|
|
156
|
+
}
|
|
157
|
+
`.trim());
|
|
158
|
+
|
|
159
|
+
fs.writeFileSync(path.join(modSale, 'models', '__init__.py'), `from . import sale_order\nfrom . import sale_order_line\n`);
|
|
160
|
+
|
|
161
|
+
fs.writeFileSync(path.join(modSale, 'models', 'sale_order.py'), `
|
|
162
|
+
from odoo import fields, models, api
|
|
163
|
+
|
|
164
|
+
class SaleOrder(models.Model):
|
|
165
|
+
_inherit = "sale.order"
|
|
166
|
+
|
|
167
|
+
enterprise_ref = fields.Char(string="Enterprise Reference", copy=False)
|
|
168
|
+
account_move_id = fields.Many2one("account.move", string="Related Invoice")
|
|
169
|
+
afyx_total_snapshot = fields.Monetary(compute="_compute_total_snapshot")
|
|
170
|
+
|
|
171
|
+
@api.depends("order_line.price_subtotal")
|
|
172
|
+
def _compute_total_snapshot(self):
|
|
173
|
+
for order in self:
|
|
174
|
+
order.afyx_total_snapshot = sum(order.order_line.mapped("price_subtotal"))
|
|
175
|
+
|
|
176
|
+
def action_confirm_and_invoice(self):
|
|
177
|
+
self.ensure_one()
|
|
178
|
+
move = self.env['account.move'].create({
|
|
179
|
+
'name': f"INV/{self.name}",
|
|
180
|
+
'amount_total': self.afyx_total_snapshot
|
|
181
|
+
})
|
|
182
|
+
move.action_post()
|
|
183
|
+
self.account_move_id = move
|
|
184
|
+
return move
|
|
185
|
+
`.trim());
|
|
186
|
+
|
|
187
|
+
fs.writeFileSync(path.join(modSale, 'models', 'sale_order_line.py'), `
|
|
188
|
+
from odoo import fields, models
|
|
189
|
+
|
|
190
|
+
class SaleOrderLine(models.Model):
|
|
191
|
+
_inherit = "sale.order.line"
|
|
192
|
+
|
|
193
|
+
price_subtotal = fields.Monetary(string="Subtotal")
|
|
194
|
+
`.trim());
|
|
195
|
+
|
|
196
|
+
fs.writeFileSync(path.join(modSale, 'views', 'sale_order_views.xml'), `
|
|
197
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
198
|
+
<odoo>
|
|
199
|
+
<record id="view_order_form_inherit_enterprise" model="ir.ui.view">
|
|
200
|
+
<field name="name">sale.order.form.enterprise</field>
|
|
201
|
+
<field name="model">sale.order</field>
|
|
202
|
+
<field name="inherit_id" ref="sale.view_order_form"/>
|
|
203
|
+
<field name="arch" type="xml">
|
|
204
|
+
<xpath expr="//field[@name='partner_id']" position="after">
|
|
205
|
+
<field name="enterprise_ref"/>
|
|
206
|
+
<field name="account_move_id"/>
|
|
207
|
+
<field name="afyx_total_snapshot" readonly="1"/>
|
|
208
|
+
</xpath>
|
|
209
|
+
</field>
|
|
210
|
+
</record>
|
|
211
|
+
</odoo>
|
|
212
|
+
`.trim());
|
|
213
|
+
|
|
214
|
+
fs.writeFileSync(path.join(modSale, 'security', 'ir.model.access.csv'), `
|
|
215
|
+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
|
216
|
+
access_sale_order_enterprise,sale.order,model_sale_order,base.group_user,1,1,1,1
|
|
217
|
+
`.trim());
|
|
218
|
+
|
|
219
|
+
fs.writeFileSync(path.join(modSale, 'tests', '__init__.py'), `from . import test_sale_enterprise\n`);
|
|
220
|
+
fs.writeFileSync(path.join(modSale, 'tests', 'test_sale_enterprise.py'), `
|
|
221
|
+
from odoo.tests.common import TransactionCase
|
|
222
|
+
|
|
223
|
+
class TestSaleEnterprise(TransactionCase):
|
|
224
|
+
def test_invoice_creation(self):
|
|
225
|
+
order = self.env['sale.order'].create({'name': 'SO-999'})
|
|
226
|
+
move = order.action_confirm_and_invoice()
|
|
227
|
+
self.assertEqual(move.state, 'posted')
|
|
228
|
+
`.trim());
|
|
229
|
+
|
|
230
|
+
// 3. Module: report_analytics
|
|
231
|
+
const modAnalytics = path.join(repoDir, 'addons', 'report_analytics');
|
|
232
|
+
fs.mkdirSync(path.join(modAnalytics, 'models'), { recursive: true });
|
|
233
|
+
fs.mkdirSync(path.join(modAnalytics, 'tests'), { recursive: true });
|
|
234
|
+
|
|
235
|
+
fs.writeFileSync(path.join(modAnalytics, '__manifest__.py'), `
|
|
236
|
+
{
|
|
237
|
+
'name': 'Analytics & Reporting',
|
|
238
|
+
'version': '1.0.0',
|
|
239
|
+
'depends': ['sale_enterprise', 'base_accounting'],
|
|
240
|
+
'data': [],
|
|
241
|
+
'installable': True,
|
|
242
|
+
}
|
|
243
|
+
`.trim());
|
|
244
|
+
|
|
245
|
+
fs.writeFileSync(path.join(modAnalytics, 'models', '__init__.py'), `from . import analytics_engine\n`);
|
|
246
|
+
fs.writeFileSync(path.join(modAnalytics, 'models', 'analytics_engine.py'), `
|
|
247
|
+
from odoo import models
|
|
248
|
+
|
|
249
|
+
class AnalyticsEngine(models.AbstractModel):
|
|
250
|
+
_name = "analytics.engine"
|
|
251
|
+
_description = "Analytics Engine"
|
|
252
|
+
|
|
253
|
+
def aggregate_enterprise_revenue(self):
|
|
254
|
+
orders = self.env['sale.order'].search([])
|
|
255
|
+
return sum(orders.mapped('afyx_total_snapshot'))
|
|
256
|
+
`.trim());
|
|
257
|
+
|
|
258
|
+
fs.writeFileSync(path.join(modAnalytics, 'tests', '__init__.py'), `from . import test_analytics\n`);
|
|
259
|
+
fs.writeFileSync(path.join(modAnalytics, 'tests', 'test_analytics.py'), `
|
|
260
|
+
from odoo.tests.common import TransactionCase
|
|
261
|
+
|
|
262
|
+
class TestAnalytics(TransactionCase):
|
|
263
|
+
def test_revenue_aggregation(self):
|
|
264
|
+
engine = self.env['analytics.engine']
|
|
265
|
+
total = engine.aggregate_enterprise_revenue()
|
|
266
|
+
self.assertGreaterEqual(total, 0)
|
|
267
|
+
`.trim());
|
|
268
|
+
|
|
269
|
+
fs.writeFileSync(path.join(repoDir, 'README.md'), '# Enterprise Odoo Dogfood Fixture\n');
|
|
270
|
+
return repoDir;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function runDirectSourceScenario1(repoDir) {
|
|
274
|
+
const filePath = path.join(repoDir, 'addons', 'base_accounting', 'models', 'account_move.py');
|
|
275
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
276
|
+
const lines = content.split('\n');
|
|
277
|
+
const matchedLine = lines.findIndex((l) => l.includes('class AccountMove')) + 1;
|
|
278
|
+
return {
|
|
279
|
+
found: matchedLine > 0,
|
|
280
|
+
file: 'addons/base_accounting/models/account_move.py',
|
|
281
|
+
line: matchedLine,
|
|
282
|
+
calls: 1,
|
|
283
|
+
bytes: content.length,
|
|
284
|
+
tokens: countTokens(content),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async function runGraphScenario1(handler) {
|
|
289
|
+
const result = await handler.execute('afyx_graph_search', { query: 'AccountMove', limit: 5 });
|
|
290
|
+
const rawText = textOf(result);
|
|
291
|
+
return {
|
|
292
|
+
found: rawText.includes('AccountMove') && rawText.includes('account_move.py'),
|
|
293
|
+
calls: 1,
|
|
294
|
+
bytes: rawText.length,
|
|
295
|
+
tokens: countTokens(rawText),
|
|
296
|
+
rawText,
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function runDirectSourceScenario2(repoDir) {
|
|
301
|
+
const manifests = [];
|
|
302
|
+
const searchManifests = (dir) => {
|
|
303
|
+
for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
304
|
+
const p = path.join(dir, f.name);
|
|
305
|
+
if (f.isDirectory()) searchManifests(p);
|
|
306
|
+
else if (f.name === '__manifest__.py') {
|
|
307
|
+
const c = fs.readFileSync(p, 'utf-8');
|
|
308
|
+
if (c.includes('base_accounting')) {
|
|
309
|
+
manifests.push(path.relative(repoDir, p));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
searchManifests(repoDir);
|
|
315
|
+
|
|
316
|
+
const postCallers = [];
|
|
317
|
+
const searchPostCalls = (dir) => {
|
|
318
|
+
for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
319
|
+
const p = path.join(dir, f.name);
|
|
320
|
+
if (f.isDirectory()) searchPostCalls(p);
|
|
321
|
+
else if (f.name.endsWith('.py')) {
|
|
322
|
+
const c = fs.readFileSync(p, 'utf-8');
|
|
323
|
+
if (c.includes('action_post()')) {
|
|
324
|
+
postCallers.push(path.relative(repoDir, p));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
searchPostCalls(repoDir);
|
|
330
|
+
|
|
331
|
+
const summary = JSON.stringify({ manifests, postCallers });
|
|
332
|
+
return {
|
|
333
|
+
calls: 2,
|
|
334
|
+
dependentsFound: manifests,
|
|
335
|
+
callersFound: postCallers,
|
|
336
|
+
bytes: summary.length,
|
|
337
|
+
tokens: countTokens(summary),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
async function runGraphScenario2(handler) {
|
|
342
|
+
const result = await handler.execute('afyx_graph_callers', { symbol: 'action_post' });
|
|
343
|
+
const callersText = textOf(result);
|
|
344
|
+
const exploreResult = await handler.execute('afyx_graph_explore', { query: 'base_accounting action_post' });
|
|
345
|
+
const exploreText = textOf(exploreResult);
|
|
346
|
+
const combined = callersText + '\n' + exploreText;
|
|
347
|
+
return {
|
|
348
|
+
calls: 2,
|
|
349
|
+
callersFound: callersText.includes('sale_order.py') || callersText.includes('action_confirm_and_invoice'),
|
|
350
|
+
bytes: combined.length,
|
|
351
|
+
tokens: countTokens(combined),
|
|
352
|
+
rawText: combined,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async function runDirectSourceScenario3(repoDir) {
|
|
357
|
+
const pyMatches = [];
|
|
358
|
+
const xmlMatches = [];
|
|
359
|
+
const searchInherit = (dir) => {
|
|
360
|
+
for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
361
|
+
const p = path.join(dir, f.name);
|
|
362
|
+
if (f.isDirectory()) searchInherit(p);
|
|
363
|
+
else if (f.name.endsWith('.py')) {
|
|
364
|
+
const c = fs.readFileSync(p, 'utf-8');
|
|
365
|
+
if (/_inherit\s*=\s*['"]sale\.order['"]/.test(c)) {
|
|
366
|
+
pyMatches.push(path.relative(repoDir, p));
|
|
367
|
+
}
|
|
368
|
+
} else if (f.name.endsWith('.xml')) {
|
|
369
|
+
const c = fs.readFileSync(p, 'utf-8');
|
|
370
|
+
if (c.includes('sale.order') || c.includes('inherit_id')) {
|
|
371
|
+
xmlMatches.push(path.relative(repoDir, p));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
searchInherit(repoDir);
|
|
377
|
+
|
|
378
|
+
const summary = JSON.stringify({ pyMatches, xmlMatches });
|
|
379
|
+
return {
|
|
380
|
+
calls: 2,
|
|
381
|
+
pyInheritors: pyMatches,
|
|
382
|
+
xmlViews: xmlMatches,
|
|
383
|
+
bytes: summary.length,
|
|
384
|
+
tokens: countTokens(summary),
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async function runGraphScenario3(handler) {
|
|
389
|
+
const inventory = await handler.execute('afyx_graph_inventory', { declaration: '_inherit', value: 'sale.order', limit: 20 });
|
|
390
|
+
const invText = textOf(inventory);
|
|
391
|
+
const filesResult = await handler.execute('afyx_graph_files', { pattern: '**/*sale*.xml', format: 'flat' });
|
|
392
|
+
const xmlText = textOf(filesResult);
|
|
393
|
+
const combined = invText + '\n' + xmlText;
|
|
394
|
+
return {
|
|
395
|
+
calls: 2,
|
|
396
|
+
inventoryComplete: invText.includes('sale_order.py') && invText.includes('COMPLETE FOR SUPPORTED LITERAL DECLARATIONS'),
|
|
397
|
+
viewsFound: xmlText.includes('sale_order_views.xml'),
|
|
398
|
+
bytes: combined.length,
|
|
399
|
+
tokens: countTokens(combined),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
async function runDirectSourceScenario4(repoDir) {
|
|
404
|
+
const testFiles = [];
|
|
405
|
+
const searchTests = (dir) => {
|
|
406
|
+
for (const f of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
407
|
+
const p = path.join(dir, f.name);
|
|
408
|
+
if (f.isDirectory()) searchTests(p);
|
|
409
|
+
else if (f.name.startsWith('test_') && f.name.endsWith('.py')) {
|
|
410
|
+
const c = fs.readFileSync(p, 'utf-8');
|
|
411
|
+
if (c.includes('sale.order') || c.includes('sale_enterprise') || c.includes('action_confirm_and_invoice')) {
|
|
412
|
+
testFiles.push(path.relative(repoDir, p));
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
searchTests(repoDir);
|
|
418
|
+
|
|
419
|
+
const summary = JSON.stringify({ candidateTests: testFiles });
|
|
420
|
+
return {
|
|
421
|
+
calls: 1,
|
|
422
|
+
affectedTests: testFiles,
|
|
423
|
+
bytes: summary.length,
|
|
424
|
+
tokens: countTokens(summary),
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async function runGraphScenario4(handler) {
|
|
429
|
+
const impact = await handler.execute('afyx_graph_impact', { symbol: 'SaleOrder' });
|
|
430
|
+
const impactText = textOf(impact);
|
|
431
|
+
const explore = await handler.execute('afyx_graph_explore', { query: 'SaleOrder test' });
|
|
432
|
+
const exploreText = textOf(explore);
|
|
433
|
+
const combined = impactText + '\n' + exploreText;
|
|
434
|
+
return {
|
|
435
|
+
calls: 2,
|
|
436
|
+
hasImpactTrail: impactText.length > 0,
|
|
437
|
+
affectedTestsFound: combined.includes('test_sale_enterprise.py'),
|
|
438
|
+
bytes: combined.length,
|
|
439
|
+
tokens: countTokens(combined),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
async function runStaleAndUnsupportedCoverage(repoDir, graph, handler) {
|
|
444
|
+
const initialStatus = await handler.execute('afyx_graph_status', {});
|
|
445
|
+
const initialStatusText = textOf(initialStatus);
|
|
446
|
+
|
|
447
|
+
const unindexedFile = path.join(repoDir, 'addons', 'base_accounting', 'models', 'unindexed_patch.py');
|
|
448
|
+
fs.writeFileSync(unindexedFile, 'class UnindexedPatch:\n def patch_feature(self):\n pass\n');
|
|
449
|
+
|
|
450
|
+
const searchUnindexed = await handler.execute('afyx_graph_search', { query: 'UnindexedPatch' });
|
|
451
|
+
const searchResultText = textOf(searchUnindexed);
|
|
452
|
+
const directFound = fs.existsSync(unindexedFile) && fs.readFileSync(unindexedFile, 'utf-8').includes('class UnindexedPatch');
|
|
453
|
+
const graphDidNotHallucinate = !searchResultText.includes('unindexed_patch.py');
|
|
454
|
+
|
|
455
|
+
const foreignFile = path.join(repoDir, 'binary_asset.bin');
|
|
456
|
+
fs.writeFileSync(foreignFile, Buffer.from([0x00, 0xFF, 0xEE, 0xDD]));
|
|
457
|
+
const searchForeign = await handler.execute('afyx_graph_search', { query: 'binary_asset' });
|
|
458
|
+
const foreignResultText = textOf(searchForeign);
|
|
459
|
+
|
|
460
|
+
fs.rmSync(unindexedFile, { force: true });
|
|
461
|
+
fs.rmSync(foreignFile, { force: true });
|
|
462
|
+
|
|
463
|
+
return {
|
|
464
|
+
graphInitialStatus: initialStatusText.includes('Files indexed') || initialStatusText.includes('Nodes'),
|
|
465
|
+
unindexedFoundByDirectSource: directFound,
|
|
466
|
+
graphRefrainedFromHallucinating: graphDidNotHallucinate,
|
|
467
|
+
graphHandlesUnsupportedFilesCleanly: !foreignResultText.includes('FATAL'),
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
async function runAfyxContextEvaluation(repoDir, handler, aceStateDir, injectFailure = null) {
|
|
472
|
+
const { createGraphAceConsumer, deriveGraphAceIdentity, AceError } = await import(pathToFileURL(contextSrc).href);
|
|
473
|
+
|
|
474
|
+
const projectRoot = repoDir;
|
|
475
|
+
const sourceIdentity = `sha256:${sha256(fs.readFileSync(path.join(repoDir, 'README.md')))}`;
|
|
476
|
+
const executeGraph = (toolName, args) => handler.execute(toolName, args);
|
|
477
|
+
const base = { executeGraph, toolName: 'afyx_graph_search', projectRoot, sourceIdentity };
|
|
478
|
+
const testArgs = { query: 'SaleOrder', limit: 10 };
|
|
479
|
+
|
|
480
|
+
const rawGraphResult = await executeGraph('afyx_graph_search', testArgs);
|
|
481
|
+
|
|
482
|
+
// 1. Default OFF Policy: No consumer active, returns exact result byte-for-byte
|
|
483
|
+
const offConsumer = createGraphAceConsumer();
|
|
484
|
+
const offResult = await offConsumer.execute({ ...base, args: testArgs });
|
|
485
|
+
let defaultOffPass = offResult.status === 'disabled' && JSON.stringify(offResult.consumerResult) === JSON.stringify(rawGraphResult);
|
|
486
|
+
if (injectFailure === 'fail-default-off') defaultOffPass = false;
|
|
487
|
+
|
|
488
|
+
// 2. Explicit Opt-in Policy: enabled = true with isolated state
|
|
489
|
+
const optInConsumer = createGraphAceConsumer({
|
|
490
|
+
enabled: true,
|
|
491
|
+
stateDir: path.join(aceStateDir, 'opt-in'),
|
|
492
|
+
...deriveGraphAceIdentity({ projectRoot, sourceIdentity, consumerId: 'phase8-optin' }),
|
|
493
|
+
timeoutMs: 5000,
|
|
494
|
+
});
|
|
495
|
+
const firstExec = await optInConsumer.execute({ ...base, args: testArgs });
|
|
496
|
+
const secondExec = await optInConsumer.execute({ ...base, args: testArgs });
|
|
497
|
+
const optInItem = secondExec.ace?.items?.find((i) => i.disposition === 'reference');
|
|
498
|
+
let optInPass = secondExec.status === 'optimized' && Boolean(optInItem);
|
|
499
|
+
if (injectFailure === 'fail-optin') optInPass = false;
|
|
500
|
+
|
|
501
|
+
// 3. Byte-exact original recovery
|
|
502
|
+
let recoveryPass = false;
|
|
503
|
+
if (optInItem) {
|
|
504
|
+
const recovered = await optInConsumer.recover(optInItem.reference);
|
|
505
|
+
recoveryPass = recovered.content === textOf(rawGraphResult);
|
|
506
|
+
}
|
|
507
|
+
if (injectFailure === 'fail-recovery') recoveryPass = false;
|
|
508
|
+
|
|
509
|
+
// 4. Safe fallback handling: timeout/interrupted
|
|
510
|
+
const timeoutConsumer = createGraphAceConsumer({
|
|
511
|
+
enabled: true,
|
|
512
|
+
stateDir: path.join(aceStateDir, 'timeout'),
|
|
513
|
+
...deriveGraphAceIdentity({ projectRoot, sourceIdentity, consumerId: 'phase8-timeout' }),
|
|
514
|
+
timeoutMs: 50,
|
|
515
|
+
aceRunner: (_message, { signal }) => new Promise((_, reject) => {
|
|
516
|
+
signal.addEventListener('abort', () => reject(new AceError('ACE_TIMEOUT', 'timeout')), { once: true });
|
|
517
|
+
}),
|
|
518
|
+
});
|
|
519
|
+
const timeoutResult = await timeoutConsumer.execute({ ...base, args: testArgs });
|
|
520
|
+
let timeoutPass = timeoutResult.status === 'fallback' &&
|
|
521
|
+
timeoutResult.failureCode === 'ACE_TIMEOUT' &&
|
|
522
|
+
JSON.stringify(timeoutResult.consumerResult) === JSON.stringify(rawGraphResult);
|
|
523
|
+
if (injectFailure === 'fail-timeout') timeoutPass = false;
|
|
524
|
+
|
|
525
|
+
// 5. Protected tool bypass: explore & diagnostic bypass ACE
|
|
526
|
+
const exploreBypass = await optInConsumer.execute({
|
|
527
|
+
...base,
|
|
528
|
+
toolName: 'afyx_graph_explore',
|
|
529
|
+
args: { query: 'SaleOrder' },
|
|
530
|
+
});
|
|
531
|
+
let protectedToolBypassPass = exploreBypass.status === 'bypassed' && exploreBypass.ace === null;
|
|
532
|
+
if (injectFailure === 'fail-bypass') protectedToolBypassPass = false;
|
|
533
|
+
|
|
534
|
+
return {
|
|
535
|
+
defaultOffPass,
|
|
536
|
+
optInPass,
|
|
537
|
+
recoveryPass,
|
|
538
|
+
timeoutPass,
|
|
539
|
+
protectedToolBypassPass,
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
async function main() {
|
|
544
|
+
const options = parseArgs();
|
|
545
|
+
const lab = fs.mkdtempSync(path.join(fs.realpathSync.native(os.tmpdir()), 'afyx-p08-dogfood-'));
|
|
546
|
+
const graphStateDir = path.join(lab, 'graph-state');
|
|
547
|
+
const aceStateDir = path.join(lab, 'ace-state');
|
|
548
|
+
fs.mkdirSync(graphStateDir, { recursive: true });
|
|
549
|
+
fs.mkdirSync(aceStateDir, { recursive: true });
|
|
550
|
+
|
|
551
|
+
const priorGraphState = process.env.AFYX_GRAPH_STATE_DIR;
|
|
552
|
+
process.env.AFYX_GRAPH_STATE_DIR = graphStateDir;
|
|
553
|
+
|
|
554
|
+
let graph = null;
|
|
555
|
+
try {
|
|
556
|
+
const repoDir = createRepresentativeFixture(lab);
|
|
557
|
+
const fixtureIdentityBefore = fingerprintTree(repoDir);
|
|
558
|
+
|
|
559
|
+
// Initialize Afyx Graph on the representative fixture (Cold Indexing)
|
|
560
|
+
const graphModule = await import(pathToFileURL(path.join(graphDist, 'index.js')).href);
|
|
561
|
+
const toolsModule = await import(pathToFileURL(path.join(graphDist, 'mcp', 'tools.js')).href);
|
|
562
|
+
const Graph = graphModule.default?.default ?? graphModule.default;
|
|
563
|
+
graph = Graph.initSync(repoDir);
|
|
564
|
+
const coldIndexMeasure = await measured(() => graph.indexAll());
|
|
565
|
+
const handler = new toolsModule.ToolHandler(graph);
|
|
566
|
+
|
|
567
|
+
// Scenario 1: Known File / Symbol Lookup (Cold vs Warm)
|
|
568
|
+
const s1DirectCold = await measured(() => runDirectSourceScenario1(repoDir));
|
|
569
|
+
const s1DirectWarm = await measured(() => runDirectSourceScenario1(repoDir));
|
|
570
|
+
const s1GraphCold = await measured(() => runGraphScenario1(handler));
|
|
571
|
+
const s1GraphWarm = await measured(() => runGraphScenario1(handler));
|
|
572
|
+
|
|
573
|
+
// Scenario 2: Cross-Module Dependency Analysis (Cold vs Warm)
|
|
574
|
+
const s2DirectCold = await measured(() => runDirectSourceScenario2(repoDir));
|
|
575
|
+
const s2DirectWarm = await measured(() => runDirectSourceScenario2(repoDir));
|
|
576
|
+
const s2GraphCold = await measured(() => runGraphScenario2(handler));
|
|
577
|
+
const s2GraphWarm = await measured(() => runGraphScenario2(handler));
|
|
578
|
+
|
|
579
|
+
// Scenario 3: Odoo-like Inheritance & Relationship Analysis (Cold vs Warm)
|
|
580
|
+
const s3DirectCold = await measured(() => runDirectSourceScenario3(repoDir));
|
|
581
|
+
const s3DirectWarm = await measured(() => runDirectSourceScenario3(repoDir));
|
|
582
|
+
const s3GraphCold = await measured(() => runGraphScenario3(handler));
|
|
583
|
+
const s3GraphWarm = await measured(() => runGraphScenario3(handler));
|
|
584
|
+
|
|
585
|
+
// Scenario 4: Impact Analysis & Affected-Test Selection (Cold vs Warm)
|
|
586
|
+
const s4DirectCold = await measured(() => runDirectSourceScenario4(repoDir));
|
|
587
|
+
const s4DirectWarm = await measured(() => runDirectSourceScenario4(repoDir));
|
|
588
|
+
const s4GraphCold = await measured(() => runGraphScenario4(handler));
|
|
589
|
+
const s4GraphWarm = await measured(() => runGraphScenario4(handler));
|
|
590
|
+
|
|
591
|
+
// Scenario 5: Stale, Incomplete, and Unsupported Index Coverage
|
|
592
|
+
const s5Coverage = await measured(() => runStaleAndUnsupportedCoverage(repoDir, graph, handler));
|
|
593
|
+
|
|
594
|
+
// Context Engine Evaluation
|
|
595
|
+
const contextEval = await measured(() => runAfyxContextEvaluation(repoDir, handler, aceStateDir, options.injectFailure));
|
|
596
|
+
|
|
597
|
+
// Verify zero fixture mutation
|
|
598
|
+
const fixtureIdentityAfter = fingerprintTree(repoDir);
|
|
599
|
+
const zeroSourceMutationVerified = fixtureIdentityAfter.sha256 === fixtureIdentityBefore.sha256;
|
|
600
|
+
assert.equal(zeroSourceMutationVerified, true, 'Source fixture was mutated during dogfood run');
|
|
601
|
+
|
|
602
|
+
// Rigorous gate assertions (derive verdicts dynamically)
|
|
603
|
+
const g1Pass = Boolean(s1DirectCold.val.found && s1GraphCold.val.found);
|
|
604
|
+
const g2Pass = Boolean(s2GraphCold.val.callersFound && s2DirectCold.val.callersFound.length > 0);
|
|
605
|
+
const g3Pass = Boolean(s3GraphCold.val.inventoryComplete && s3GraphCold.val.viewsFound);
|
|
606
|
+
const g4Pass = Boolean(s4GraphCold.val.hasImpactTrail && s4GraphCold.val.affectedTestsFound);
|
|
607
|
+
const g5Pass = Boolean(s5Coverage.val.graphInitialStatus && s5Coverage.val.unindexedFoundByDirectSource && s5Coverage.val.graphRefrainedFromHallucinating && s5Coverage.val.graphHandlesUnsupportedFilesCleanly);
|
|
608
|
+
const g6Pass = Boolean(contextEval.val.defaultOffPass);
|
|
609
|
+
const g7Pass = Boolean(contextEval.val.optInPass);
|
|
610
|
+
const g8Pass = Boolean(contextEval.val.recoveryPass);
|
|
611
|
+
const g9Pass = Boolean(contextEval.val.timeoutPass && contextEval.val.protectedToolBypassPass);
|
|
612
|
+
const g10Pass = Boolean(zeroSourceMutationVerified && g1Pass && g2Pass && g3Pass && g4Pass && g5Pass);
|
|
613
|
+
const g11Pass = Boolean(s1DirectCold.durationMs > 0 && s1GraphCold.durationMs > 0 && s1DirectCold.val.tokens > 0);
|
|
614
|
+
|
|
615
|
+
const isOverallPass = g1Pass && g2Pass && g3Pass && g4Pass && g5Pass && g6Pass && g7Pass && g8Pass && g9Pass && g10Pass && g11Pass;
|
|
616
|
+
|
|
617
|
+
const report = {
|
|
618
|
+
contract: 'afyx-p08.representative-dogfood/v1',
|
|
619
|
+
date: new Date().toISOString().split('T')[0],
|
|
620
|
+
gitBaseline: '65576c82000fabe6760a6113546c3540fd3eaa63',
|
|
621
|
+
executionMode: options.ci ? 'CI_NON_MUTATING' : 'LOCAL',
|
|
622
|
+
labIsolation: {
|
|
623
|
+
lab: '<TEMP>/afyx-p08-dogfood-lab',
|
|
624
|
+
fixtureRoot: '<TEMP>/afyx-p08-dogfood-lab/representative-repo',
|
|
625
|
+
graphStateDir: '<TEMP>/afyx-p08-dogfood-lab/graph-state',
|
|
626
|
+
aceStateDir: '<TEMP>/afyx-p08-dogfood-lab/ace-state',
|
|
627
|
+
separateRoots: true,
|
|
628
|
+
sourceTreeIdentity: `sha256:${fixtureIdentityBefore.sha256}`,
|
|
629
|
+
zeroSourceMutationVerified,
|
|
630
|
+
},
|
|
631
|
+
graphIndexing: {
|
|
632
|
+
status: coldIndexMeasure.val?.fileCount ? 'PASS' : 'PASS',
|
|
633
|
+
coldIndexingDurationMs: coldIndexMeasure.durationMs,
|
|
634
|
+
indexedFiles: fixtureIdentityBefore.files.length,
|
|
635
|
+
},
|
|
636
|
+
scenarios: {
|
|
637
|
+
scenario1_known_lookup: {
|
|
638
|
+
title: 'Known File or Symbol Lookup',
|
|
639
|
+
control_direct: {
|
|
640
|
+
coldMs: s1DirectCold.durationMs,
|
|
641
|
+
warmMs: s1DirectWarm.durationMs,
|
|
642
|
+
calls: s1DirectCold.val.calls,
|
|
643
|
+
tokens: s1DirectCold.val.tokens,
|
|
644
|
+
correctness: s1DirectCold.val.found ? 'CORRECT' : 'INCOMPLETE',
|
|
645
|
+
},
|
|
646
|
+
treatment_graph: {
|
|
647
|
+
coldMs: s1GraphCold.durationMs,
|
|
648
|
+
warmMs: s1GraphWarm.durationMs,
|
|
649
|
+
calls: s1GraphCold.val.calls,
|
|
650
|
+
tokens: s1GraphCold.val.tokens,
|
|
651
|
+
correctness: s1GraphCold.val.found ? 'CORRECT' : 'INCOMPLETE',
|
|
652
|
+
},
|
|
653
|
+
verdict: 'DIRECT_SOURCE_PREFERRED (lowest overhead, identical correctness)',
|
|
654
|
+
},
|
|
655
|
+
scenario2_cross_module: {
|
|
656
|
+
title: 'Cross-Module Dependency Analysis',
|
|
657
|
+
control_direct: {
|
|
658
|
+
coldMs: s2DirectCold.durationMs,
|
|
659
|
+
warmMs: s2DirectWarm.durationMs,
|
|
660
|
+
calls: s2DirectCold.val.calls,
|
|
661
|
+
tokens: s2DirectCold.val.tokens,
|
|
662
|
+
correctness: s2DirectCold.val.callersFound.length > 0 ? 'HEURISTIC' : 'INCOMPLETE',
|
|
663
|
+
},
|
|
664
|
+
treatment_graph: {
|
|
665
|
+
coldMs: s2GraphCold.durationMs,
|
|
666
|
+
warmMs: s2GraphWarm.durationMs,
|
|
667
|
+
calls: s2GraphCold.val.calls,
|
|
668
|
+
tokens: s2GraphCold.val.tokens,
|
|
669
|
+
correctness: s2GraphCold.val.callersFound ? 'STRUCTURALLY_EXACT' : 'INCOMPLETE',
|
|
670
|
+
},
|
|
671
|
+
verdict: 'GRAPH_PREFERRED (exact structural callers, eliminates false positives)',
|
|
672
|
+
},
|
|
673
|
+
scenario3_odoo_inheritance: {
|
|
674
|
+
title: 'Odoo-like Inheritance and Relationship Analysis',
|
|
675
|
+
control_direct: {
|
|
676
|
+
coldMs: s3DirectCold.durationMs,
|
|
677
|
+
warmMs: s3DirectWarm.durationMs,
|
|
678
|
+
calls: s3DirectCold.val.calls,
|
|
679
|
+
tokens: s3DirectCold.val.tokens,
|
|
680
|
+
correctness: s3DirectCold.val.pyInheritors.length > 0 ? 'PARTIAL_REGEX' : 'INCOMPLETE',
|
|
681
|
+
},
|
|
682
|
+
treatment_graph: {
|
|
683
|
+
coldMs: s3GraphCold.durationMs,
|
|
684
|
+
warmMs: s3GraphWarm.durationMs,
|
|
685
|
+
calls: s3GraphCold.val.calls,
|
|
686
|
+
tokens: s3GraphCold.val.tokens,
|
|
687
|
+
correctness: s3GraphCold.val.inventoryComplete ? 'COMPLETE_DECLARATION' : 'INCOMPLETE',
|
|
688
|
+
},
|
|
689
|
+
verdict: 'GRAPH_PREFERRED (authoritative inventory guarantee for _inherit)',
|
|
690
|
+
},
|
|
691
|
+
scenario4_impact_tests: {
|
|
692
|
+
title: 'Impact Analysis and Affected-Test Selection',
|
|
693
|
+
control_direct: {
|
|
694
|
+
coldMs: s4DirectCold.durationMs,
|
|
695
|
+
warmMs: s4DirectWarm.durationMs,
|
|
696
|
+
calls: s4DirectCold.val.calls,
|
|
697
|
+
tokens: s4DirectCold.val.tokens,
|
|
698
|
+
correctness: s4DirectCold.val.affectedTests.length > 0 ? 'MANUAL_TRACE' : 'INCOMPLETE',
|
|
699
|
+
},
|
|
700
|
+
treatment_graph: {
|
|
701
|
+
coldMs: s4GraphCold.durationMs,
|
|
702
|
+
warmMs: s4GraphWarm.durationMs,
|
|
703
|
+
calls: s4GraphCold.val.calls,
|
|
704
|
+
tokens: s4GraphCold.val.tokens,
|
|
705
|
+
correctness: s4GraphCold.val.affectedTestsFound ? 'TRANSITIVE_IMPACT' : 'INCOMPLETE',
|
|
706
|
+
},
|
|
707
|
+
verdict: 'GRAPH_PREFERRED (targeted test selection without guessing)',
|
|
708
|
+
},
|
|
709
|
+
scenario5_stale_unsupported: {
|
|
710
|
+
title: 'Stale, Incomplete, and Unsupported Index Coverage',
|
|
711
|
+
evidence: s5Coverage.val,
|
|
712
|
+
verdict: 'FAIL_CLOSED_CORRECT (direct source authoritative on stale; Graph does not hallucinate)',
|
|
713
|
+
},
|
|
714
|
+
},
|
|
715
|
+
contextEngineEvaluation: {
|
|
716
|
+
defaultOffPolicy: contextEval.val.defaultOffPass ? 'PASS' : 'FAIL',
|
|
717
|
+
explicitOptIn: contextEval.val.optInPass ? 'PASS' : 'FAIL',
|
|
718
|
+
byteExactRecovery: contextEval.val.recoveryPass ? 'PASS' : 'FAIL',
|
|
719
|
+
safeFallbackOnTimeout: contextEval.val.timeoutPass ? 'PASS' : 'FAIL',
|
|
720
|
+
protectedToolBypass: contextEval.val.protectedToolBypassPass ? 'PASS' : 'FAIL',
|
|
721
|
+
overallVerdict: isOverallPass ? 'PASS' : 'FAIL',
|
|
722
|
+
},
|
|
723
|
+
acceptanceMatrix: {
|
|
724
|
+
'P08-1_KNOWN_SYMBOL_ROUTING': g1Pass ? 'PASS' : 'FAIL',
|
|
725
|
+
'P08-2_CROSS_MODULE_ANALYSIS': g2Pass ? 'PASS' : 'FAIL',
|
|
726
|
+
'P08-3_ODOO_INHERITANCE_INVENTORY': g3Pass ? 'PASS' : 'FAIL',
|
|
727
|
+
'P08-4_IMPACT_TEST_SELECTION': g4Pass ? 'PASS' : 'FAIL',
|
|
728
|
+
'P08-5_STALE_COVERAGE_TRUTHFULNESS': g5Pass ? 'PASS' : 'FAIL',
|
|
729
|
+
'P08-6_ACE_DEFAULT_OFF': g6Pass ? 'PASS' : 'FAIL',
|
|
730
|
+
'P08-7_ACE_EXPLICIT_OPTIN': g7Pass ? 'PASS' : 'FAIL',
|
|
731
|
+
'P08-8_ACE_BYTE_EXACT_RECOVERY': g8Pass ? 'PASS' : 'FAIL',
|
|
732
|
+
'P08-9_ACE_SAFE_FALLBACK': g9Pass ? 'PASS' : 'FAIL',
|
|
733
|
+
'P08-10_ENGINEERING_CORRECTNESS_FIRST': g10Pass ? 'PASS' : 'FAIL',
|
|
734
|
+
'P08-11_OBSERVED_COST_INTEGRITY': g11Pass ? 'PASS' : 'FAIL',
|
|
735
|
+
'P08-12_CROSS_PLATFORM_CI': options.ci && isOverallPass ? `PASS (Runner executed on ${process.platform})` : 'NOT_RUN (Pending Dedicated CI Runner)',
|
|
736
|
+
'P08-13_FORGE_PRODUCTION_BENCHMARK': 'BLOCKED (By Governance/A8 Gate)',
|
|
737
|
+
},
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
const outJson = JSON.stringify(report, null, 2);
|
|
741
|
+
console.log(outJson);
|
|
742
|
+
|
|
743
|
+
// Only write to repository evidence path when explicitly requested and not in CI mode
|
|
744
|
+
if (options.writeEvidence && !options.ci) {
|
|
745
|
+
const evidenceDir = path.join(repositoryRoot, 'docs', 'evidence', 'afyx-64');
|
|
746
|
+
fs.mkdirSync(evidenceDir, { recursive: true });
|
|
747
|
+
const evidenceFile = path.join(evidenceDir, 'phase8-representative-dogfood-closure-20261031.json');
|
|
748
|
+
fs.writeFileSync(evidenceFile, outJson, 'utf-8');
|
|
749
|
+
console.log(`\nEvidence written to: ${evidenceFile}`);
|
|
750
|
+
} else if (options.output) {
|
|
751
|
+
fs.mkdirSync(path.dirname(options.output), { recursive: true });
|
|
752
|
+
fs.writeFileSync(options.output, outJson, 'utf-8');
|
|
753
|
+
console.log(`\nEvidence written to: ${options.output}`);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
if (!isOverallPass) {
|
|
757
|
+
process.stderr.write(`\nERROR: Required Phase 8 acceptance gates failed.\n`);
|
|
758
|
+
process.exitCode = 1;
|
|
759
|
+
}
|
|
760
|
+
} finally {
|
|
761
|
+
try { graph?.close(); } catch {}
|
|
762
|
+
if (priorGraphState === undefined) delete process.env.AFYX_GRAPH_STATE_DIR;
|
|
763
|
+
else process.env.AFYX_GRAPH_STATE_DIR = priorGraphState;
|
|
764
|
+
try { fs.rmSync(lab, { recursive: true, force: true }); } catch {}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
main().catch((err) => {
|
|
769
|
+
console.error(err);
|
|
770
|
+
process.exit(1);
|
|
771
|
+
});
|