56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
BOOTSTRAP = Path(__file__).parents[1] / "frontend" / "workspace-bootstrap.js"
|
|
|
|
|
|
def run_bootstrap(scenario: str) -> dict:
|
|
harness = f"""
|
|
const loadWorkspace = require({json.dumps(str(BOOTSTRAP))});
|
|
(async()=>{{ {scenario} }})().catch(error=>{{console.error(error);process.exit(1);}});
|
|
"""
|
|
completed = subprocess.run(
|
|
["node", "-e", harness], check=True, capture_output=True, text=True
|
|
)
|
|
return json.loads(completed.stdout)
|
|
|
|
|
|
def test_workspace_bootstrap_loads_content_addressed_feature_before_startup():
|
|
result = run_bootstrap("""
|
|
const status={textContent:''};
|
|
const document={
|
|
querySelector(selector) {
|
|
if (selector === 'meta[name="stackchain-feature-today-timer"]') return {content:'feature-workspace-abc.js'};
|
|
if (selector === '#my-work-action-status') return status;
|
|
return null;
|
|
}
|
|
};
|
|
let requested='';
|
|
const createLoader=options=>({load:async name=>{requested=name + ':' + options.urls[name];}});
|
|
await loadWorkspace({document,createLoader});
|
|
console.log(JSON.stringify({requested,status:status.textContent}));
|
|
""")
|
|
assert result == {"requested": "today-timer:feature-workspace-abc.js", "status": ""}
|
|
|
|
|
|
def test_workspace_bootstrap_keeps_shell_and_announces_retry_when_feature_fails():
|
|
result = run_bootstrap("""
|
|
const status={textContent:''};
|
|
const document={
|
|
querySelector(selector) {
|
|
if (selector === 'meta[name="stackchain-feature-today-timer"]') return {content:'feature-workspace-abc.js'};
|
|
if (selector === '#my-work-action-status') return status;
|
|
return null;
|
|
}
|
|
};
|
|
const createLoader=()=>({load:async()=>{throw new Error('network failed');}});
|
|
let message='';
|
|
try { await loadWorkspace({document,createLoader}); } catch (error) { message=error.message; }
|
|
console.log(JSON.stringify({message,status:status.textContent}));
|
|
""")
|
|
assert result == {
|
|
"message": "network failed",
|
|
"status": "Workspace could not load. Check your connection, then reload to retry.",
|
|
} |