11#!/usr/bin/env python3
22"""Exercise the published portable launcher outside this checkout; no cloud calls."""
33import os
4+ import base64
5+ import time
46import json
57from pathlib import Path
68import shutil
@@ -33,7 +35,7 @@ def main():
3335 launcher .chmod (0o700 )
3436 environment = {
3537 key : value for key , value in os .environ .items ()
36- if not key .startswith ('COLORS_PAR_' ) and key not in {
38+ if not key .startswith (( 'COLORS_PAR_' , 'OCI_' ) ) and key not in {
3739 'VIRTUAL_ENV' , 'PYTHONPATH' , 'PYTHONHOME' , 'UV_PROJECT' ,
3840 'UV_PROJECT_ENVIRONMENT' , 'UV_WORKING_DIRECTORY' ,
3941 }
@@ -45,6 +47,7 @@ def main():
4547 stub = launcher .parent / command
4648 stub .write_text (guard )
4749 stub .chmod (0o700 )
50+ environment ['OCI_CLI_CONFIG_FILE' ] = str (root / 'oci-config' )
4851 environment ['PATH' ] = str (launcher .parent ) + os .pathsep + environment .get ('PATH' , '' )
4952
5053 def invoke (directory , * arguments , expected = None , successful = False ):
@@ -95,6 +98,10 @@ def invoke(directory, *arguments, expected=None, successful=False):
9598 fresh .mkdir ()
9699 (fresh / 'colors.yml' ).write_text (CONFIG .replace ('compute-require-existing-state: true' ,
97100 'compute-require-existing-state: false' ))
101+ conflicting = invoke (fresh , 'init' , '--json' , '--verbose' , '--quiet' , expected = '' )
102+ conflict_envelope = json .loads (conflicting .stdout )
103+ assert conflicting .returncode == 2 and conflict_envelope ['ok' ] is False
104+ assert not (fresh / '.colors.sqlite' ).exists (), 'Conflicting flags initialized state.'
98105 initialized_run = invoke (fresh , 'init' , '--json' , '--quiet' , successful = True )
99106 initialized_envelope = json .loads (initialized_run .stdout )
100107 assert initialized_envelope ['schema_version' ] == 1
@@ -109,6 +116,9 @@ def invoke(directory, *arguments, expected=None, successful=False):
109116 repeated = json .loads (invoke (fresh , 'init' , '--json' , '--quiet' , successful = True ).stdout )['result' ]
110117 assert initialized ['deployment_id' ] == repeated ['deployment_id' ]
111118 assert contents == [path .read_bytes () for path in authority ]
119+ verbose_run = invoke (fresh , 'init' , '--json' , '--verbose' , successful = True )
120+ assert json .loads (verbose_run .stdout )['ok' ] is True
121+ assert verbose_run .stderr .strip (), 'Verbose mode omitted progress.'
112122 text_run = invoke (fresh , 'init' , '--quiet' , successful = True )
113123 assert text_run .stdout .strip (), 'Quiet mode suppressed the text result.'
114124 assert text_run .stderr == '' , text_run .stderr
@@ -135,7 +145,26 @@ def invoke(directory, *arguments, expected=None, successful=False):
135145 assert usage_envelope ['error' ]['code' ] and usage_envelope ['error' ]['message' ]
136146 assert usage_json .stderr == '' , usage_json .stderr
137147
138- print ('Portable launcher: 12 checks passed (no cloud access).' )
148+ # Expired synthetic credentials must fail before the guarded OCI binary runs.
149+ token = root / 'synthetic-token'
150+ payload = base64 .urlsafe_b64encode (json .dumps ({'exp' : int (time .time ()) - 3600 }).encode ()).decode ().rstrip ('=' )
151+ token .write_text ('eyJhbGciOiJSUzI1NiJ9.' + payload + '.synthetic-signature' )
152+ Path (environment ['OCI_CLI_CONFIG_FILE' ]).write_text (
153+ '[synthetic]\n security_token_file=' + str (token ) + '\n '
154+ )
155+ started = time .monotonic ()
156+ expired_run = invoke (fresh , 'plan' , '--json' , '--verbose' , expected = '' )
157+ elapsed = time .monotonic () - started
158+ expired = json .loads (expired_run .stdout )
159+ assert expired_run .returncode == 1 and expired ['ok' ] is False
160+ assert expired ['error' ]['code' ] == 'oci_token_expired'
161+ assert 'expired' in expired ['error' ]['message' ].lower ()
162+ assert 'oci session refresh --profile synthetic' in expired ['error' ]['message' ]
163+ assert elapsed < 10 , f'Expired token failed slowly: { elapsed :.1f} s'
164+ assert token .read_text () not in expired_run .stdout + expired_run .stderr
165+ print (f'Expired synthetic OCI token rejected locally in { elapsed :.2f} s; OCI was not invoked.' )
166+
167+ print ('Portable launcher: 15 checks passed (no cloud access).' )
139168
140169
141170if __name__ == '__main__' :
0 commit comments