Fix token use across test cases

Fix token use across test cases
This commit is contained in:
abraunegg 2026-03-08 08:11:58 +11:00
commit cdb35c37f8
3 changed files with 52 additions and 0 deletions

View file

@ -1,6 +1,7 @@
from __future__ import annotations
import os
import shutil
from dataclasses import dataclass
from pathlib import Path
@ -59,6 +60,47 @@ class E2EContext:
def master_log_file(self) -> Path:
return self.out_dir / "run.log"
@property
def default_onedrive_config_dir(self) -> Path:
"""
Return the default OneDrive config directory created by the workflow.
"""
xdg_config_home = os.environ.get("XDG_CONFIG_HOME", "").strip()
if xdg_config_home:
return Path(xdg_config_home) / "onedrive"
home = os.environ.get("HOME", "").strip()
if not home:
raise RuntimeError("Neither XDG_CONFIG_HOME nor HOME is set")
return Path(home) / ".config" / "onedrive"
@property
def default_refresh_token_path(self) -> Path:
return self.default_onedrive_config_dir / "refresh_token"
def ensure_refresh_token_available(self) -> None:
if not self.default_refresh_token_path.is_file():
raise RuntimeError(
f"Required refresh_token file not found at: {self.default_refresh_token_path}"
)
def bootstrap_config_dir(self, config_dir: Path) -> Path:
"""
Create a usable OneDrive config directory for a test case by copying the
existing refresh_token into the supplied config directory.
Returns the path to the copied refresh_token.
"""
self.ensure_refresh_token_available()
ensure_directory(config_dir)
source = self.default_refresh_token_path
destination = config_dir / "refresh_token"
shutil.copy2(source, destination)
os.chmod(destination, 0o600)
return destination
def log(self, message: str) -> None:
ensure_directory(self.out_dir)
line = f"[{timestamp_now()}] {message}\n"

View file

@ -23,6 +23,9 @@ class TestCase0001BasicResync(E2ETestCase):
description = "Run a basic --sync --resync --resync-auth operation and capture the outcome"
def run(self, context: E2EContext) -> TestResult:
context.ensure_refresh_token_available()
case_work_dir = context.work_root / f"tc{self.case_id}"
case_log_dir = context.logs_dir / f"tc{self.case_id}"
state_dir = context.state_dir / f"tc{self.case_id}"

View file

@ -66,6 +66,8 @@ class TestCase0002SyncListValidation(E2ETestCase):
reset_directory(scenario_log_dir)
reset_directory(config_dir)
reset_directory(sync_root)
copied_refresh_token = context.bootstrap_config_dir(config_dir)
# Seed the local sync directory from the canonical fixture.
shutil.copytree(fixture_root, sync_root, dirs_exist_ok=True)
@ -110,8 +112,13 @@ class TestCase0002SyncListValidation(E2ETestCase):
str(stdout_file),
str(stderr_file),
str(metadata_file),
str(copied_refresh_token),
]
)
context.log(
f"Scenario {scenario.scenario_id} bootstrapped config dir: {config_dir}"
)
if result.returncode != 0:
failures.append(