fix(corporate): align runtime timestamps and require database-ready pilots
Deploy Canina / deploy (push) Failing after 1s
Deploy Canina / deploy (push) Failing after 1s
This commit is contained in:
1 parent
b642833b8b
commit
94f08b8c8a
4 files changed
+40
-7
No files matched your search
@@ -11,14 +11,22 @@ import urllib.request
|
|||||||
import corporate_runtime as r
|
import corporate_runtime as r
|
||||||
|
|
||||||
|
|
||||||
|
def pilot_environment(environ):
|
||||||
|
# Idempotency is scoped to authenticated subject: fresh keys alone are not
|
||||||
|
# enough when the disposable database is retained between manual runs.
|
||||||
|
return dict(environ, CORPORATE_API_KEY=secrets.token_hex(32),
|
||||||
|
CORPORATE_QA_API_KEY=secrets.token_hex(32),
|
||||||
|
CORPORATE_PILOT_RUN_ID=secrets.token_hex(16),
|
||||||
|
CORPORATE_TEST_DATABASE_URL='postgresql://hermes@127.0.0.1:55441/corporate_test')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
root = Path(__file__).resolve().parent.parent
|
root = Path(__file__).resolve().parent.parent
|
||||||
scratch = Path(os.environ['CORPORATE_PILOT_DIR']).resolve()
|
scratch = Path(os.environ['CORPORATE_PILOT_DIR']).resolve()
|
||||||
if not str(scratch).startswith('/opt/data/cache/scratch/'):
|
if not str(scratch).startswith('/opt/data/cache/scratch/'):
|
||||||
raise ValueError('Scratch pilot output required')
|
raise ValueError('Scratch pilot output required')
|
||||||
scratch.mkdir(parents=True, exist_ok=True, mode=0o700)
|
scratch.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||||
env = dict(os.environ, CORPORATE_API_KEY=secrets.token_hex(32), CORPORATE_QA_API_KEY=secrets.token_hex(32),
|
env = pilot_environment(os.environ)
|
||||||
CORPORATE_TEST_DATABASE_URL='postgresql://hermes@127.0.0.1:55441/corporate_test')
|
|
||||||
server = subprocess.Popen(['node', str(root/'scripts/corporate_pilot_server.cjs')], env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
server = subprocess.Popen(['node', str(root/'scripts/corporate_pilot_server.cjs')], env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
base = 'http://127.0.0.1:55442/api/admin/hermes'
|
base = 'http://127.0.0.1:55442/api/admin/hermes'
|
||||||
transcript = []
|
transcript = []
|
||||||
@@ -91,8 +99,11 @@ def main():
|
|||||||
'transcript':str(scratch/'transcript.json')}))
|
'transcript':str(scratch/'transcript.json')}))
|
||||||
finally:
|
finally:
|
||||||
server.terminate()
|
server.terminate()
|
||||||
try: server.communicate(timeout=10)
|
try: output, _ = server.communicate(timeout=10)
|
||||||
except subprocess.TimeoutExpired: server.kill();server.communicate()
|
except subprocess.TimeoutExpired:
|
||||||
|
server.kill()
|
||||||
|
output, _ = server.communicate()
|
||||||
|
(scratch/'server.log').write_bytes(output)
|
||||||
|
|
||||||
|
|
||||||
if __name__=='__main__': main()
|
if __name__=='__main__': main()
|
||||||
@@ -11,12 +11,16 @@ const { ApiKeysService } = require('../backend/src/admin/api-keys.service');
|
|||||||
const u = new URL(process.env.CORPORATE_TEST_DATABASE_URL);
|
const u = new URL(process.env.CORPORATE_TEST_DATABASE_URL);
|
||||||
if (u.hostname !== '127.0.0.1' || u.port !== '55441' || u.pathname !== '/corporate_test') throw Error('disposable DB required');
|
if (u.hostname !== '127.0.0.1' || u.port !== '55441' || u.pathname !== '/corporate_test') throw Error('disposable DB required');
|
||||||
const db = new PrismaClient({datasources:{db:{url:u.href}}});
|
const db = new PrismaClient({datasources:{db:{url:u.href}}});
|
||||||
|
await db.$connect(); // Runtime status is static; do not signal readiness without PostgreSQL.
|
||||||
|
if (await db.corporateReport.findUnique({where:{day:new Date().toISOString().slice(0,10)}})) {
|
||||||
|
throw Error('Pilot requires a fresh disposable DB: today already has a report');
|
||||||
|
}
|
||||||
const module = await Test.createTestingModule({controllers:[CorporateController], providers:[CorporateService,
|
const module = await Test.createTestingModule({controllers:[CorporateController], providers:[CorporateService,
|
||||||
{provide:PrismaService,useValue:db}, {provide:ApiKeysService,useValue:{validateKey:async key => {
|
{provide:PrismaService,useValue:db}, {provide:ApiKeysService,useValue:{validateKey:async key => {
|
||||||
const role = key === process.env.CORPORATE_API_KEY ? 'executor' : key === process.env.CORPORATE_QA_API_KEY ? 'reviewer' : null;
|
const role = key === process.env.CORPORATE_API_KEY ? 'executor' : key === process.env.CORPORATE_QA_API_KEY ? 'reviewer' : null;
|
||||||
return role ? {id:'pilot-' + role,isApiKey:true,role:'Admin',scopes:['admin']} : null;
|
return role ? {id:'pilot-' + process.env.CORPORATE_PILOT_RUN_ID + '-' + role,isApiKey:true,role:'Admin',scopes:['admin']} : null;
|
||||||
}}}]}).compile();
|
}}}]}).compile();
|
||||||
const app = module.createNestApplication({logger:false});
|
const app = module.createNestApplication({logger:['error']});
|
||||||
app.setGlobalPrefix('api');
|
app.setGlobalPrefix('api');
|
||||||
await app.listen(55442,'127.0.0.1');
|
await app.listen(55442,'127.0.0.1');
|
||||||
console.log('READY loopback test-auth Nest corporate feature');
|
console.log('READY loopback test-auth Nest corporate feature');
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Regression checks for repeatable disposable integration pilots."""
|
||||||
|
import unittest
|
||||||
|
import corporate_pilot as pilot
|
||||||
|
|
||||||
|
|
||||||
|
class PilotTests(unittest.TestCase):
|
||||||
|
def test_each_run_has_distinct_authenticated_subject_namespace(self):
|
||||||
|
first = pilot.pilot_environment({})
|
||||||
|
second = pilot.pilot_environment({})
|
||||||
|
self.assertNotEqual(first['CORPORATE_PILOT_RUN_ID'], second['CORPORATE_PILOT_RUN_ID'])
|
||||||
|
self.assertNotEqual(first['CORPORATE_API_KEY'], first['CORPORATE_QA_API_KEY'])
|
||||||
|
self.assertEqual(first['CORPORATE_TEST_DATABASE_URL'],
|
||||||
|
'postgresql://hermes@127.0.0.1:55441/corporate_test')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
@@ -28,7 +28,7 @@ def sha(data):
|
|||||||
|
|
||||||
|
|
||||||
def now():
|
def now():
|
||||||
return datetime.now(timezone.utc).isoformat()
|
return datetime.now(timezone.utc).isoformat(timespec='milliseconds').replace('+00:00', 'Z')
|
||||||
|
|
||||||
|
|
||||||
class Store:
|
class Store:
|
||||||
|
|||||||
Reference in new issue
Block a user