Complete APIEX documentary preparation and private contextual SWOT in existing dossiers

This commit is contained in:
2026-11-10 18:00:06 +02:00
parent 7476dc3430
commit 37854d0231
17 changed files with 2982 additions and 24 deletions
+18
View File
@@ -0,0 +1,18 @@
import fs from 'node:fs';
import path from 'node:path';
import assert from 'node:assert/strict';
import {createHash} from 'node:crypto';
import JSZip from 'jszip';
const out=new URL('../outputs/investment-preparation-20261110/',import.meta.url);
const read=name=>JSON.parse(fs.readFileSync(new URL(name,out),'utf8'));
const digest=bytes=>createHash('sha256').update(bytes).digest('hex');
const api=read('apiex-recovered.json'),swot=read('swot-recovered.json'),sources=read('source-changes.json'),scopes=read('opportunity-scopes.json'),history=read('history-pages.json'),security=read('archive-security.json');
const bytes=fs.readFileSync(new URL('apiex-package.zip',out)),zip=await JSZip.loadAsync(bytes),manifest=JSON.parse(await zip.file('manifesto.json').async('string'));
assert.equal(manifest.case_id,api.case.id);assert.equal(api.api_state,'decision_received');assert.deepEqual(api.apiex.external.map(x=>x.kind),['delivery','clarification','response','decision']);assert.equal(api._qa_archive.initial_sha256,api._qa_archive.after_context_change_sha256);assert.equal(digest(bytes),api._qa_archive.initial_sha256);assert.equal(manifest.export.id,api.apiex.exports[0].id);assert.deepEqual(manifest.export.prepared.context,manifest.context);assert.notEqual(manifest.context.fields.project_summary,api.context.fields.project_summary);
for(const [n,doc] of manifest.export.documents.entries()){const name='anexos/'+String(n+1).padStart(2,'0')+'-'+doc.file_name.replace(/[^\p{L}\p{N}._-]+/gu,'-');assert.equal(digest(await zip.file(name).async('nodebuffer')),doc.sha256);}
assert.equal(new Set(swot.swot.rows.map(r=>r.dimension)).size,4);assert.ok(swot.swot.rows.every(r=>r.reference&&r.date&&['documented_fact','hypothesis','unconfirmed'].includes(r.classification)));assert.equal(swot.swot.actions[0].case_id,swot.case.id);assert.equal(swot._qa_native_task.case_id,swot.case.id);assert.equal(swot._qa_native_task.title,swot.swot.actions[0].title);assert.equal(swot._qa_native_task.origin_key,'swot:'+swot.swot.actions[0].id);assert.ok(swot.swot.sources_snapshot);assert.ok(swot.history.some(h=>h.action==='swot_review'));assert.equal(sources.approved_fingerprint,sources.private_edit_fingerprint);assert.notEqual(sources.approved_fingerprint,sources.new_public_fingerprint);assert.equal(sources.withdrawal_review_required,true);assert.equal(sources.conclusions_preserved,true);assert.equal(scopes.second_version_unchanged,0);assert.equal(scopes.retired_scope_readable,true);assert.equal(scopes.retired_scope_writable,false);assert.deepEqual(history.next_versions,[2,1]);assert.equal(security.revoked_scan_cached_download_status,404);assert.ok(security.encrypted_archive_count>0);
const preview=new URL('apiex-preview/',out);fs.mkdirSync(preview,{recursive:true});
for(const entry of Object.values(zip.files)){if(entry.dir)continue;const root=path.resolve(decodeURIComponent(preview.pathname).replace(/^\/([A-Za-z]:)/,'$1')),target=path.resolve(root,entry.name);assert.ok(target.startsWith(root+path.sep));fs.mkdirSync(path.dirname(target),{recursive:true});fs.writeFileSync(target,await entry.async('nodebuffer'));}
fs.writeFileSync(new URL('swot-recovered.pretty.json',out),JSON.stringify(swot,null,2));
const proof={synthetic:true,apiEx:{path:'existing dossier → requirements → documents → review → ZIP/index/attachments → external delivery/clarification/response/decision',archive_sha256:digest(bytes),attachments_verified:manifest.export.documents.length,preserved_after_context_change:true,no_automatic_submission_or_approval:true},swot:{path:'existing context/evidence → four dimensions → review → linked native task in same dossier → recovery',private_by_default:true,classification_source_date_preserved:true,source_versions_preserved:true,changed_public_sources_require_review:true,private_source_edits_not_exposed:true,deliberate_edits_preserved:true},scope_isolation:true,historical_scopes_readable_without_reactivation:true,history_beyond25:true,malware_guard_on_archived_download:true,qa_database:'simulator_fiscal_delta_20261021_test',qa_port:55441,database_transactions:'rolled back by native test trait; QA sequences may advance',installed:false,browser_visual_review:'pending; connector unavailable',no_new_database_or_port_or_migration_or_real_account:true};
fs.writeFileSync(new URL('verification.json',out),JSON.stringify(proof,null,2));console.log(JSON.stringify(proof));
+51
View File
@@ -0,0 +1,51 @@
<?php
$root = dirname(__DIR__);
if (! in_array($argv[1] ?? '', ['test', 'analyse'], true) || basename($root) !== 'portal-investidor') {
throw new RuntimeException('Explicit local test operation required.');
}
$proofDirectory = $root.'/outputs/investment-preparation-20261110';
if (! is_dir($proofDirectory)) {
mkdir($proofDirectory, 0700, true);
}
$analysisConfiguration = "includes:\n - ../../phpstan.neon\nparameters:\n tmpDir: phpstan-cache\n";
if (! is_file($proofDirectory.'/phpstan.neon')) {
file_put_contents($proofDirectory.'/phpstan.neon', $analysisConfiguration);
}
foreach (['APP_ENV' => 'testing', 'APP_KEY' => 'base64:'.base64_encode(str_repeat('Q', 32)),
'APP_CONFIG_CACHE' => $root.'/outputs/investment-preparation-20261110/no-config.php',
'DB_CONNECTION' => 'pgsql', 'DB_HOST' => '127.0.0.1', 'DB_PORT' => '55441',
'DB_DATABASE' => 'simulator_fiscal_delta_20261021_test', 'DB_USERNAME' => 'investmoz_test', 'DB_PASSWORD' => '',
'DB_URL' => '', 'DATABASE_URL' => '', 'CACHE_STORE' => 'array', 'SESSION_DRIVER' => 'array',
'QUEUE_CONNECTION' => 'sync', 'MAIL_MAILER' => 'array', 'SUITECRM_ENABLED' => 'false'] as $key => $value) {
putenv($key.'='.$value);
$_ENV[$key] = $_SERVER[$key] = $value;
}
$pdo = new PDO('pgsql:host=127.0.0.1;port=55441;dbname=simulator_fiscal_delta_20261021_test', 'investmoz_test', '');
$identity = $pdo->query('select current_database() as name,inet_server_port() as port')->fetch(PDO::FETCH_ASSOC);
if ($identity['name'] !== 'simulator_fiscal_delta_20261021_test' || (int) $identity['port'] !== 55441) {
throw new RuntimeException('Isolated QA identity required.');
}
if ($argv[1] === 'analyse') {
$argv = ['phpstan', 'analyse', '--no-progress', '--memory-limit=512M', '--configuration='.$root.'/outputs/investment-preparation-20261110/phpstan.neon', 'app/Services/InvestmentPreparationWorkspace.php', 'app/Http/Controllers/InvestmentPreparationController.php', 'app/Services/InvestorPath.php', 'routes/investor-path.php'];
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = count($argv);
require $root.'/vendor/autoload.php';
require $root.'/vendor/phpstan/phpstan/phpstan';
exit;
}
$case = 'InvestmentPreparationWorkspaceTest';
$filter = $argv[2] ?? null;
if ($filter !== null && (strlen($filter) > 128 || ! preg_match('/^[a-zA-Z0-9_|]+$/D', $filter))) {
throw new RuntimeException('Explicit QA test filter required.');
}
$argv = ['phpunit', '-c', 'phpunit.investmoz.xml', '--do-not-cache-result', 'tests/Feature/'.$case.'.php'];
if ($filter !== null) {
$argv[] = '--filter';
$argv[] = $filter;
}
$argc = count($argv);
$_SERVER['argv'] = $argv;
$_SERVER['argc'] = $argc;
require $root.'/vendor/autoload.php';
require $root.'/vendor/phpunit/phpunit/phpunit';