Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Harness OS VM tests: ask the daemon over its socket whether it is signed in (#1462)

Bubu-Dudu-52hz61297eea4d13
diff --git a/os/tests/session_vm.py b/os/tests/session_vm.py
index fc4cd0d7b..17118b79d 100644
--- a/os/tests/session_vm.py
+++ b/os/tests/session_vm.py
@@ -257,14 +257,8 @@ print(json.dumps(snapshot))
print('Restoring graphics without restarting the computer or agent', flush=True)
vm.command('sudo systemctl restart [email protected]')
if not config['encrypt']:
+ # tty1 knows its one account and asks only its password (installer.py, password.conf).
deadline = time.monotonic() + 20
- while 'login:' not in screen_text(vm, 'recovery-console-login'):
- if time.monotonic() >= deadline:
- raise AssertionError('The unencrypted installed console did not offer login')
- time.sleep(.25)
- vm.type_probe(config['username'])
- vm.keys('ret')
- deadline = time.monotonic() + 10
while 'password:' not in screen_text(vm, 'recovery-console-password'):
if time.monotonic() >= deadline:
raise AssertionError('The restored console did not request its account password')
diff --git a/os/tests/vm.py b/os/tests/vm.py
index 2ff019237..e95219417 100644
--- a/os/tests/vm.py
+++ b/os/tests/vm.py
@@ -90,6 +90,9 @@ print('HN_LIVE_MEDIA=' + json.dumps(dict(mode=mode, payload=str(payload), payloa
# the repository's secrets (HARNESS_TEST_EMAIL, HARNESS_TEST_OTP), never from this public file.
ACCOUNT_API = 'https://apiv2.autonomous.ai'
HARNESS_API = 'https://harness-api.autonomous.ai'
+# Real model replies (--model-calls): a free model's speed and wording are another service's, so an
+# ordinary run checks only what the image does, and asks a model nothing.
+MODEL_CALLS = False
def account_ticket():
@@ -335,11 +338,11 @@ class VM:
self.shell_ready = True
self.command('stty -echo')
if not config['encrypt']:
- for word in [config['username'], config['password']]:
- for char in word:
- self.keys('minus' if char == '-' else char)
- self.keys('ret')
- time.sleep(2)
+ # tty1 knows its one account and asks only its password (installer.py, password.conf).
+ for char in config['password']:
+ self.keys('minus' if char == '-' else char)
+ self.keys('ret')
+ time.sleep(2)
if wait_workspace:
self.command('for n in $(seq 1 90); do systemctl --user is-active --quiet hn-screen && pgrep -x "hn|harness-tui" >/dev/null && exit 0; sleep 1; done; exit 1', timeout=110)
self.command('/usr/lib/harness-os/wait-runtime', timeout=160)
@@ -384,7 +387,10 @@ class VM:
pass
if status or any(result.get('status') == 'error' for result in results):
raise RuntimeError('The test account sign-in failed: ' + json.dumps(results[-1:] or output[-300:]))
- self.command('for n in $(seq 1 60); do curl -s http://127.0.0.1:18473/api/status | '
+ # Asked over the daemon's own socket, as wait-runtime does: over the loopback port a caller
+ # without the local credential is told only which daemon this is, never `signedIn`.
+ self.command('for n in $(seq 1 60); do s=$(curl -s http://127.0.0.1:18473/api/status | jq -r ".localSocket // empty"); '
+ '[ -S "$s" ] && curl -s --unix-socket "$s" http://localhost/api/status | '
'grep -q \'"signedIn":true\' && exit 0; sleep 1; done; exit 1', timeout=75)
# Signed in from outside hn (as a phone's setup does), hn learns it at its next account check,
# at most a minute away: the page leaves once it has.
@@ -835,6 +841,33 @@ def check_first_use(vm, user, folder, installed=False):
vm.command(user('sh -c ' + shlex.quote('for n in $(seq 1 30); do hn capture-pane -p | grep -q "Repeat password" && exit 0; sleep 1; done; exit 1')), timeout=40)
vm.command('test "$(lsblk -n -o TYPE /dev/vda | wc -l)" -eq 1')
vm.keys('esc')
+ project_name = 'first-project' if installed else 'usb-trial'
+ trial_project = agent_path + '/' + project_name + '/index.html'
+ if not MODEL_CALLS:
+ # The visible agent takes keyboard input; the project a person would have it make is written
+ # here instead, so the installation that follows still has trial work to preserve.
+ draft = 'hello harness keyboard check'
+ vm.type_probe(draft)
+ _, typed_status = vm.command(user('sh -c ' + shlex.quote(
+ 'for n in $(seq 1 30); do hn capture-pane -p | grep -Fq ' + shlex.quote(draft) + ' && exit 0; '
+ 'sleep 1; done; exit 1')), timeout=40, check=False)
+ vm.screenshot('01e-first-agent-input')
+ assert typed_status == 0, 'The visible bundled agent must accept keyboard input'
+ for _ in draft:
+ vm.keys('backspace')
+ vm.command(user('sh -c ' + shlex.quote(
+ 'mkdir -p ' + shlex.quote(str(Path(trial_project).parent)) +
+ ' && printf "<h1>hello harness</h1>\\n" > ' + shlex.quote(trial_project))))
+ (folder / 'trial-project.html').write_bytes(vm.read_file(trial_project))
+ if installed:
+ return trial_project
+ vm.keys('ctrl', 'c')
+ time.sleep(.3)
+ vm.keys('ctrl', 'c')
+ vm.command(user('sh -c ' + shlex.quote('for n in $(seq 1 60); do '
+ 'hn list-panes -a -F "#{pane_id}" | grep -Fx ' + shlex.quote(agent_pane.group(1)) +
+ ' >/dev/null || exit 0; sleep .25; done; exit 1')), timeout=20)
+ return trial_project
# Exercise what a first-time user actually does after choosing Try: type
# into the visible agent and receive its answer, without a CLI/API shortcut.
vm.type_probe('what is six times seven reply with digits only')
@@ -863,8 +896,6 @@ def check_first_use(vm, user, folder, installed=False):
assert guide_status == 0, 'Bundled OpenCode must explain the actual OS shortcuts from its local guide'
# Build inside the actual per-agent project, as a person does. A sibling
# directory would instead exercise OpenCode's external-directory permission.
- project_name = 'first-project' if installed else 'usb-trial'
- trial_project = agent_path + '/' + project_name + '/index.html'
vm.type_probe('create the folder ' + project_name + ' in this project and an index html page inside it saying hello harness')
vm.keys('ret')
vm.command('for n in $(seq 1 120); do test -s ' + shlex.quote(trial_project) + ' && '
@@ -1080,7 +1111,10 @@ def main():
parser.add_argument('--workload-seed', type=Path, help='Previous workload artifact: preserve its generated projects and rerun acceptance')
parser.add_argument('--workload-repair-game', action='store_true', help='With a seed, explicitly ask the agent to repair game layout before rechecking')
parser.add_argument('--live-only', action='store_true', help='Development probe: stop after the live-session checks, without installing')
+ parser.add_argument('--model-calls', action='store_true', help='Also ask the bundled agent real questions (a free model) on first use')
args = parser.parse_args()
+ global MODEL_CALLS
+ MODEL_CALLS = args.model_calls or args.workloads or args.dsh
if args.expect_live_mode and args.live_transport != 'usb':
parser.error('--expect-live-mode requires --live-transport usb')
if args.workloads and not args.agents: