From e69d5f0a0d0d3745ceafc38d59ec3b603cc6d56d Mon Sep 17 00:00:00 2001 From: Denozordec Date: Sat, 21 Nov 2026 01:51:32 +0700 Subject: [PATCH] =?UTF-8?q?fix(db):=20maintenance-inspect=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=81=D0=BB=D0=B5=D0=B4=D1=83=D0=B5=D1=82=20=D0=B1=D0=B0=D0=B7?= =?UTF-8?q?=D1=83=20=D1=81=20=D0=BF=D1=80=D0=BE=D1=84=D0=B8=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=20source58?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Наблюдение текущего состояния снимало схему только по public. Источник 58 ставит на таблицы public триггеры с функциями mmapp_control, и захват отказывал на внешних зависимостях («Duplicate catalog row: unsupported»), поэтому старт backend после MCP-восстановления нельзя было открыть. При наличии mmapp_control область теперь та же, что у runtime: public и mmapp_control со служебными event-триггерами. Co-Authored-By: Claude Opus 5.5 --- backend/scripts/database-maintenance-resolution.test.mts | 4 ++-- backend/scripts/writer-profile/maintenance-resolution.mts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/scripts/database-maintenance-resolution.test.mts b/backend/scripts/database-maintenance-resolution.test.mts index 407ba3e1..c01ee4aa 100644 --- a/backend/scripts/database-maintenance-resolution.test.mts +++ b/backend/scripts/database-maintenance-resolution.test.mts @@ -30,7 +30,7 @@ async function model(root:string,localHost?:string){ const files={sha:hash,protectedDirectory,readProtected:async(file:string,maximum:number,pin?:string)=>{assert(file.startsWith(root+path.sep));const raw=await readFile(file);assert(raw.length>0&&raw.length<=maximum);if(pin)assert.equal(hash(raw),pin);return raw},writeFile:async(file:string,raw:Buffer)=>{assert(file.startsWith(root+path.sep));await writeFile(file,raw,{flag:'wx'});published++},withJournalLease:async(directory:string,work:()=>Promise)=>{const lock=path.join(directory,'publisher-lease.lock');await writeFile(lock,'owned',{flag:'wx'});try{return await work()}finally{await unlink(lock)}}} const readRecords=async(directory:string)=>{const records=path.join(directory,'maintenance-acceptances');let names:string[];try{names=await readdir(records)}catch(error){if((error as NodeJS.ErrnoException).code==='ENOENT')return [];throw error};assert(names.every(name=>/^[a-f0-9-]{36}\.json$/.test(name)));return Promise.all(names.sort().map(name=>readFile(path.join(records,name))))} const moduleFile=path.join(backend,'scripts/writer-profile/maintenance-resolution.mts'),sourceText=(await readFile(moduleFile,'utf8')).replaceAll('import.meta.url',JSON.stringify(pathToFileURL(moduleFile).href)),exports:Record={} - const dependencies:Record={'./operator-files.mjs':files,'./operator-contract.mjs':contract,'../../src/services/database-maintenance-startup.js':{...strictReader,readMaintenanceAcceptanceRecords:readRecords},'../../src/services/database-maintenance-resolution.js':grammar,'../../src/db/migration-schema-inventory.js':{captureMigrationSchema:async(_client:unknown,options:{scope:unknown})=>{capturedScopes.push(options.scope);return schema}},'../../src/db/migration-manifest.js':manifest,pg:{Pool}} + const dependencies:Record={'./operator-files.mjs':files,'./operator-contract.mjs':contract,'../../src/services/database-maintenance-startup.js':{...strictReader,readMaintenanceAcceptanceRecords:readRecords},'../../src/services/database-maintenance-resolution.js':grammar,'../../src/db/migration-schema-inventory.js':{captureMigrationSchema:async(_client:unknown,options:{scope:unknown;includeControlEventTriggers?:boolean})=>{capturedScopes.push({...options.scope as object,includeControlEventTriggers:options.includeControlEventTriggers});return schema}},'../../src/db/migration-manifest.js':manifest,pg:{Pool}} const code=ts.transpileModule(sourceText,{compilerOptions:{module:ts.ModuleKind.CommonJS,target:ts.ScriptTarget.ES2022,esModuleInterop:true}}).outputText runInNewContext(code,{exports,require:(name:string)=>name in dependencies?dependencies[name]:require(name),Buffer,URL,process:{env:{}},Date,Object,Map,Set,Error,console}) const command=exports.maintenanceMain as (args:string[])=>Promise> @@ -93,7 +93,7 @@ test('local mode explicitly disables SSL/environment substitution; TLS remains v // A normal installation has no optional writer-profile schema. Observation must // select its exact namespace set without requiring installation of that system. test('maintenance observes with and without the optional control namespace',async()=>{ - for(const present of [false,true])await own(async root=>{const fixture=await model(root);if(present)fixture.withControlSchema();await fixture.inspect();assert.equal(JSON.stringify(fixture.scopes()),JSON.stringify([{applicationNamespaces:['public'],excludedControlNamespaces:present?['mmapp_control']:[]}]))}) + for(const present of [false,true])await own(async root=>{const fixture=await model(root);if(present)fixture.withControlSchema();await fixture.inspect();assert.equal(JSON.stringify(fixture.scopes()),JSON.stringify([{applicationNamespaces:present?['public','mmapp_control']:['public'],includeControlEventTriggers:present}]))}) }) test('original observation failure survives confirmed rollback/unlock/release',()=>own(async root=>{ const fixture=await model(root),failure=Error('Synthetic original observation failure');fixture.failObservation(failure);await assert.rejects(fixture.inspect(),error=>error===failure);assert.equal(fixture.published(),0);assert.equal((await fixture.readRecords(fixture.state)).length,0) diff --git a/backend/scripts/writer-profile/maintenance-resolution.mts b/backend/scripts/writer-profile/maintenance-resolution.mts index b08935d6..6371baa2 100644 --- a/backend/scripts/writer-profile/maintenance-resolution.mts +++ b/backend/scripts/writer-profile/maintenance-resolution.mts @@ -66,7 +66,10 @@ export async function observeMaintenanceCurrent(pool:Pick,transp // detailed capture still refuses every other unexpected namespace. const control=await query("SELECT nspname FROM pg_catalog.pg_namespace WHERE nspname='mmapp_control'") assert(control.rows.length<=1&&control.rows.every(row=>row.nspname==='mmapp_control')) - const schema=await captureMigrationSchema({query:async(text,values)=>query(text,values)},{scope:{applicationNamespaces:['public'],excludedControlNamespaces:control.rows.length?['mmapp_control']:[]},deadlineAt:Date.now()+60000}) + // Same scope as the runtime catalogue snapshot: source58 places public triggers on mmapp_control functions, which a + // public-only capture reports as unsupported external dependencies. + const withControl=control.rows.length===1 + const schema=await captureMigrationSchema({query:async(text,values)=>query(text,values)},{scope:{applicationNamespaces:withControl?['public','mmapp_control']:['public']},includeControlEventTriggers:withControl,deadlineAt:Date.now()+60000}) const marker=schema.sections.relations.find(row=>row.namespace==='public'&&row.name==='schema_migrations'),column=schema.sections.columns.find(row=>row.namespace==='public'&&row.relation==='schema_migrations'&&row.name==='id'&&row.dropped===false) assert(marker?.kind==='r'&&marker.persistence==='p'&&marker.row_security===false&&marker.force_row_security===false&&column?.type==='text') for(const table of CURRENT_REQUIRED_TABLES)assert(schema.sections.relations.some(row=>row.namespace==='public'&&row.name===table&&['r','p'].includes(String(row.kind))&&row.row_security===false&&row.force_row_security===false))