fix(corporate): detach no-input migration Docker stdin
Deploy Canina / deploy (push) Failing after 27s
Deploy Canina / deploy (push) Failing after 27s
This commit is contained in:
1 parent
90dcec413d
commit
bee9c4d6e1
6 files changed
+73
-4
No files matched your search
@@ -18,6 +18,21 @@ SQL = (m.ROOT / f'backend/prisma/migrations/{m.NAME}/migration.sql').read_bytes(
|
||||
|
||||
|
||||
class Transport(unittest.TestCase):
|
||||
def test_docker_stdin_contract(self):
|
||||
# Background PTY jobs must never inherit terminal stdin without a payload.
|
||||
# This checks the subprocess boundary, not real Docker/job-control behavior.
|
||||
for data in (None, b'SELECT 1;\n', b''):
|
||||
with self.subTest(data=data), patch.object(m.subprocess, 'run') as run:
|
||||
run.return_value = subprocess.CompletedProcess([], 0, stdout=b'ok')
|
||||
self.assertEqual(m.stage('command', data=data), b'ok')
|
||||
args, kwargs = run.call_args
|
||||
self.assertEqual(args[0], ['docker', 'exec', '-i', m.DB, 'sh', '-ec', 'command'])
|
||||
self.assertEqual(kwargs.get('stdin'), subprocess.DEVNULL if data is None else None)
|
||||
self.assertEqual(kwargs['input'], data)
|
||||
self.assertEqual(kwargs['stdout'], subprocess.PIPE)
|
||||
self.assertEqual(kwargs['stderr'], subprocess.PIPE)
|
||||
self.assertEqual(kwargs['timeout'], 600)
|
||||
|
||||
def test_gate_faults_and_order(self):
|
||||
for failure in ('backup', 'restore', 'clone-apply', 'digest', None):
|
||||
with self.subTest(failure=failure), tempfile.TemporaryDirectory() as td:
|
||||
@@ -63,10 +78,15 @@ class Transport(unittest.TestCase):
|
||||
class Result:
|
||||
returncode = 1 if failure == 'restore' else 0
|
||||
def restore(*args, **kwargs):
|
||||
self.assertIs(kwargs['stdin'], Source.stdout)
|
||||
events.append('restore'); return Result()
|
||||
def source(*args, **kwargs):
|
||||
self.assertEqual(kwargs.get('stdin'), subprocess.DEVNULL)
|
||||
self.assertEqual(kwargs['stdout'], subprocess.PIPE)
|
||||
return Source()
|
||||
with patch.object(m, 'ROOT', root), patch.object(m, 'docker', fake), patch.dict(
|
||||
os.environ, GITHUB_ACTIONS='true', DEPLOY_SHA='a' * 40), patch.object(
|
||||
m.subprocess, 'Popen', return_value=Source()), patch.object(m.subprocess, 'run', restore):
|
||||
m.subprocess, 'Popen', side_effect=source), patch.object(m.subprocess, 'run', restore):
|
||||
if failure:
|
||||
with self.assertRaises(RuntimeError): m.run()
|
||||
self.assertNotIn('live', events)
|
||||
|
||||
@@ -19,8 +19,11 @@ ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
def docker(*args, data=None, timeout=600):
|
||||
# Do not relay stderr: tools may expose connection details or row data.
|
||||
result = subprocess.run(['docker', *args], input=data, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, timeout=timeout)
|
||||
# No-payload calls must not read a background job's controlling terminal.
|
||||
# run(input=...) creates PIPE for payloads, including empty bytes.
|
||||
result = subprocess.run(['docker', *args], input=data,
|
||||
stdin=subprocess.DEVNULL if data is None else None,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
|
||||
if result.returncode:
|
||||
raise RuntimeError('Docker operation failed: ' + args[0])
|
||||
return result.stdout
|
||||
@@ -126,7 +129,8 @@ def run():
|
||||
else:
|
||||
raise RuntimeError('Restore server readiness timeout')
|
||||
# Stream full backup, never store its sensitive contents in runner logs/memory.
|
||||
source = subprocess.Popen(['docker', 'exec', DB, 'cat', backup], stdout=subprocess.PIPE,
|
||||
source = subprocess.Popen(['docker', 'exec', DB, 'cat', backup],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL)
|
||||
try:
|
||||
assert source.stdout is not None
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
# Verification
|
||||
|
||||
## RED (before implementation)
|
||||
`python3 scripts/corporate-stage-migrate-test.py Transport` exited 1: ran 3 tests, FAILED (failures=5). No-payload docker helper and four backup source subcases asserted `None != -3` (DEVNULL). Payload and empty-byte contracts already passed. An earlier draft used dictionary indexing and produced KeyError for omitted stdin; assertions were refined to compare the effective inherited default using kwargs.get before the definitive RED run.
|
||||
|
||||
## GREEN
|
||||
`python3 scripts/corporate-stage-migrate-test.py` exited 0: ran 4 tests in 5.635s, OK. Includes real disposable local PostgreSQL transaction, rollback, lock contention, idempotency, checksum guard, full backup/restore; transport fault/order tests; stdin contract; pipeline order. Transport success output is from test doubles, not a real Stage migration. PostgreSQL fixture starts/stops only its newly created local scratch server, not existing CI/release processes.
|
||||
|
||||
`git diff --check` exited 0. Tests prove the explicit subprocess stdin contract (authorised alternative to actual PTY background reproduction), not the originating stop signal or successful live Docker/Stage recovery. SQL input remains passed through run(input=data), which creates PIPE for both nonempty and empty bytes; restore stdin remains the source stdout stream. No timeout, error sanitation, target, transaction or lock behavior changed.
|
||||
|
||||
## Release boundary
|
||||
Local tests only; no push/deploy, production/cron changes, cancellation, existing process signals, lock deletion or live migration invocation. Parent must integrate and manage owner cancellation before next CI. Existing graph query modified this isolated worktree's cache stamp only; restore that generated modification before commit. No whole-app build or live CI acceptance claimed for this Python-only change.
|
||||
@@ -0,0 +1,14 @@
|
||||
# Plan
|
||||
|
||||
Read engineering, Graphify and Spec-Kit skills and baseline constitution (v1.1.0). Existing worktree has no tracked .specify configuration; do not overwrite shared scaffolding. Use proportional feature artifacts only.
|
||||
|
||||
## Impact map
|
||||
Base clean isolated branch corporate-migration-stdin at 90dcec413d243ae84359c52db4307b0bac1f7a8e. Existing graph SHA256 6a73473cee9e207543fdeeb668bea544f766200a1b16b8a3a9ce18d4e42e51af, 4304 nodes. Graph build/source binding unverified; query `corporate-stage-migrate docker stage subprocess stdin` returns only deployment/Compose nodes. Treat as navigation only. Direct source confirms run -> stage -> docker -> subprocess.run; apply_stage and clone psql use data bytes. Backup source Popen separately inherits stdin; restore consumes its stdout. No frontend/backend code changes.
|
||||
|
||||
## Implementation
|
||||
1. Add explicit subprocess argument regression for absent payload, SQL bytes and empty bytes before implementation; assert backup source uses DEVNULL and restore retains stream stdin in existing transport test.
|
||||
2. Set stdin=DEVNULL only when data is None (input=None is compatible with explicit stdin); for payload use stdin=None so subprocess.run(input=data) creates PIPE. Set backup source Popen stdin=DEVNULL. Preserve restore stream wiring.
|
||||
3. Run focused tests RED, then GREEN and complete existing script suite; inspect diff, commit only owned paths. No release/build is needed for Python-only helper; this is not live Docker/PTY or Stage acceptance.
|
||||
|
||||
## Consistency
|
||||
Acceptance, file ownership, and tests align; no CI/process changes or pushes authorised.
|
||||
@@ -0,0 +1,12 @@
|
||||
# Corporate migration noninteractive stdin
|
||||
|
||||
## Intent and acceptance
|
||||
CI migration transport must not consume the controlling terminal when running in a background job-control group. No-payload Docker operations must receive EOF via DEVNULL; SQL payloads, including empty bytes, must retain subprocess input piping. Full backup restore must continue streaming source stdout to restore stdin. Preserve timeouts, sanitised errors, fixed Stage target, backup and migration guards.
|
||||
|
||||
Regression acceptance: explicit subprocess stdin contract tests fail on base and pass after the fix; existing transport and real PostgreSQL transaction/restore tests remain green where local tools are available. Unit doubles verify transport arguments, not live Docker or Stage recovery.
|
||||
|
||||
## Boundaries
|
||||
Only scripts/corporate-stage-migrate.py, scripts/corporate-stage-migrate-test.py and this feature's Markdown are owned. No push, deployment, cron changes, existing process manipulation or lock deletion; run1343/task1586 remains owner-controlled.
|
||||
|
||||
## Evidence and decisions
|
||||
Base: 90dcec413d243ae84359c52db4307b0bac1f7a8e. Diagnostic: /opt/data/cache/scratch/stage-90dcec4-receipt.json records stopped Python/Docker with PTY stdin, not a captured originating signal. Source confirms docker(input=None) inherited stdin in no-payload stage exec -i. Explicit subprocess contract regression is authorised instead of a PTY integration fixture. No unresolved business decisions.
|
||||
@@ -0,0 +1,7 @@
|
||||
# Tasks
|
||||
|
||||
- [x] Inspect exact base, diagnostic, engineering baseline and graph/source impact.
|
||||
- [x] Specify stdin acceptance and bounded local-only scope before code changes.
|
||||
- [x] Add explicit subprocess contracts and execute RED before implementation.
|
||||
- [x] Apply minimal stdin fix and execute GREEN plus existing suite (4 tests OK).
|
||||
- [x] Record evidence and review owned diff; commit only owned paths, no push or deployment.
|
||||
Reference in new issue
Block a user