()
| 5 | |
| 6 | |
| 7 | def main(): |
| 8 | call('init', '--no-vault') |
| 9 | check('fixture is native-only (no Git repository)', not (ROOT / '.git').exists()) |
| 10 | (ROOT / '.atomicignore').write_bytes(b'cache/\n') |
| 11 | (ROOT / 'source.txt').write_bytes(b'source view\n') |
| 12 | (ROOT / 'source.txt').chmod(0o755) |
| 13 | call('add', '.atomicignore', 'source.txt') |
| 14 | record('source') |
| 15 | source = view() |
| 16 | (ROOT / 'cache').mkdir() |
| 17 | (ROOT / 'cache/state.txt').write_bytes(b'source cache\n') |
| 18 | call('view', 'create', 'target', '--draft', '--parent', source, '--switch') |
| 19 | (ROOT / 'nested').mkdir(exist_ok=True) |
| 20 | (ROOT / 'nested/target.txt').write_bytes(b'target view\n') |
| 21 | call('add', 'nested/target.txt') |
| 22 | record('target') |
| 23 | (ROOT / 'cache').mkdir(exist_ok=True) |
| 24 | (ROOT / 'cache/state.txt').write_bytes(b'target cache\n') |
| 25 | call('view', 'switch', source, '--force') |
| 26 | (ROOT / 'untracked.txt').write_bytes(b'undecided user work\n') |
| 27 | working_copy = (ROOT / '.atomic/working_copy_id').read_text().strip() |
| 28 | shelves = ROOT / '.atomic/working-copies' / working_copy / 'workspaces' |
| 29 | check('source ignored artifact is materialized', (ROOT / 'cache/state.txt').read_bytes() == b'source cache\n') |
| 30 | check('target ignored artifact is shelved', any('target' in p and row for p, row in files_under(shelves).items())) |
| 31 | |
| 32 | for phase, diagnostic in [ |
| 33 | ('AFTER_PUBLISH', 'injected switch failure after view publication'), |
| 34 | ('AFTER_MATERIALIZE', 'injected switch failure after materialization'), |
| 35 | ]: |
| 36 | baseline_files = files_under(ROOT) |
| 37 | baseline_shelves = files_under(shelves) |
| 38 | histories = {name: data('log', '--view', name, '--all', '--format', 'json') for name in (source, 'target')} |
| 39 | old_log = data('op', 'log', '--json') |
| 40 | old_ids = {entry['id'] for entry in old_log['entries']} |
| 41 | result = call('view', 'switch', 'target', '--force', |
| 42 | env={'ATOMIC_TEST_FAIL_SWITCH_' + phase: '1'}, success=False) |
| 43 | check(phase + ': requested failure seam actually fires', result.returncode != 0 and diagnostic in result.stderr.decode() + result.stdout.decode()) |
| 44 | |
| 45 | # Inspect BEFORE any writable retry: switch_view_with_operation performs |
| 46 | # its inverse recovery synchronously on a returned error. |
| 47 | log = data('op', 'log', '--json') |
| 48 | added = [entry for entry in log['entries'] if entry['id'] not in old_ids] |
| 49 | failed = [entry for entry in added if entry['kind'] == 'switch_view'] |
| 50 | check(phase + ': failed switch is durably journaled once', len(failed) == 1) |
| 51 | heads = [entry for entry in log['entries'] if entry['is_head']] |
| 52 | check(phase + ': inverse recovery is the verified head before retry', |
| 53 | len(heads) == 1 and heads[0]['kind'] == 'recover' and heads[0]['verification'] == 'verified') |
| 54 | recovery = data('op', 'show', heads[0]['id'], '--json') |
| 55 | check(phase + ': inverse recovery links to failed switch', failed[0]['id'] in recovery['parents']) |
| 56 | check(phase + ': recovery has a verified receipt', any(r['kind'] == 'verified' for r in recovery['receipts'])) |
| 57 | original = data('op', 'show', failed[0]['id'], '--json') |
| 58 | check(phase + ': original plan leases the working copy', any(e['target']['kind'] == 'working_copy' for e in original['delta']['effects'])) |
| 59 | check(phase + ': original plan leases target materialization', any(e['target'].get('path') == 'nested/target.txt' for e in original['delta']['effects'])) |
| 60 | check(phase + ': ignored artifacts have shelf leases', any(e['target']['kind'] == 'shelf_path' for e in original['delta']['effects'])) |
| 61 | check(phase + ': files, links and modes already restored', files_under(ROOT) == baseline_files) |
| 62 | check(phase + ': both views shelves restored', files_under(shelves) == baseline_shelves) |
| 63 | check(phase + ': source view restored', view() == source) |
| 64 | check(phase + ': target-only content absent after rollback', not (ROOT / 'nested/target.txt').exists()) |
no test coverage detected