Skip to content

Commit 23ba241

Browse files
committed
fix for log tracking
1 parent 5652f28 commit 23ba241

File tree

4 files changed

+80
-56
lines changed

4 files changed

+80
-56
lines changed

sdk.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,13 +1220,29 @@ class TestDriverSDK {
12201220

12211221
// If dashcam is available and recording, add web logs for this domain
12221222
if (this._dashcam) {
1223+
1224+
// Create the log file on the remote machine
1225+
const shell = this.os === "windows" ? "pwsh" : "sh";
1226+
const logPath = this.os === "windows"
1227+
? "C:\\Users\\testdriver\\Documents\\testdriver.log"
1228+
: "/tmp/testdriver.log";
1229+
1230+
const createLogCmd = this.os === "windows"
1231+
? `New-Item -ItemType File -Path "${logPath}" -Force | Out-Null`
1232+
: `touch ${logPath}`;
1233+
1234+
await this.exec(shell, createLogCmd, 10000, true);
1235+
12231236
console.log('[provision.chrome] Adding web logs to dashcam...');
12241237
try {
12251238
const urlObj = new URL(url);
12261239
const domain = urlObj.hostname;
12271240
const pattern = `*${domain}*`;
12281241
await this._dashcam.addWebLog(pattern, 'Web Logs');
12291242
console.log(`[provision.chrome] ✅ Web logs added to dashcam (pattern: ${pattern})`);
1243+
1244+
await this._dashcam.addFileLog(logPath, "TestDriver Log");
1245+
12301246
} catch (error) {
12311247
console.warn('[provision.chrome] ⚠️ Failed to add web logs:', error.message);
12321248
}

src/vitest/hooks.mjs

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ import TestDriverSDK from '../../sdk.js';
2929
* @param {string} taskId - Unique task identifier for this test
3030
*/
3131
function setupConsoleSpy(client, taskId) {
32-
// Determine log file path based on OS
33-
const logPath = client.os === "windows"
34-
? "C:\\Users\\testdriver\\Documents\\testdriver.log"
35-
: "/tmp/testdriver.log";
3632

37-
// Store log path on client for later use
38-
client._testLogPath = logPath;
33+
// Debug logging for console spy setup
34+
const debugConsoleSpy = process.env.TD_DEBUG_CONSOLE_SPY === 'true';
35+
if (debugConsoleSpy) {
36+
process.stdout.write(`[DEBUG setupConsoleSpy] taskId: ${taskId}\n`);
37+
process.stdout.write(`[DEBUG setupConsoleSpy] client.sandbox exists: ${!!client.sandbox}\n`);
38+
process.stdout.write(`[DEBUG setupConsoleSpy] client.sandbox?.instanceSocketConnected: ${client.sandbox?.instanceSocketConnected}\n`);
39+
process.stdout.write(`[DEBUG setupConsoleSpy] client.sandbox?.send: ${typeof client.sandbox?.send}\n`);
40+
}
41+
42+
// Track forwarding stats
43+
let forwardedCount = 0;
44+
let skippedCount = 0;
3945

4046
// Helper to forward logs to sandbox
4147
const forwardToSandbox = (args) => {
@@ -49,10 +55,25 @@ function setupConsoleSpy(client, taskId) {
4955

5056
// Send to sandbox for immediate visibility in dashcam
5157
if (client.sandbox && client.sandbox.instanceSocketConnected) {
52-
client.sandbox.send({
53-
type: "output",
54-
output: Buffer.from(message, "utf8").toString("base64"),
55-
});
58+
try {
59+
client.sandbox.send({
60+
type: "output",
61+
output: Buffer.from(message, "utf8").toString("base64"),
62+
});
63+
forwardedCount++;
64+
if (debugConsoleSpy && forwardedCount <= 3) {
65+
process.stdout.write(`[DEBUG forwardToSandbox] Forwarded message #${forwardedCount}: "${message.substring(0, 50)}..."\n`);
66+
}
67+
} catch (err) {
68+
if (debugConsoleSpy) {
69+
process.stdout.write(`[DEBUG forwardToSandbox] Error sending: ${err.message}\n`);
70+
}
71+
}
72+
} else {
73+
skippedCount++;
74+
if (debugConsoleSpy && skippedCount <= 3) {
75+
process.stdout.write(`[DEBUG forwardToSandbox] SKIPPED (sandbox not connected): "${message.substring(0, 50)}..."\n`);
76+
}
5677
}
5778
};
5879

@@ -159,14 +180,25 @@ export function TestDriver(context, options = {}) {
159180

160181
// Auto-connect if enabled (default: true)
161182
const autoConnect = config.autoConnect !== undefined ? config.autoConnect : true;
183+
const debugConsoleSpy = process.env.TD_DEBUG_CONSOLE_SPY === 'true';
184+
162185
if (autoConnect) {
163186
testdriver.__connectionPromise = (async () => {
164187
try {
165188
console.log('[testdriver] Connecting to sandbox...');
189+
if (debugConsoleSpy) {
190+
console.log('[DEBUG] Before auth - sandbox.instanceSocketConnected:', testdriver.sandbox?.instanceSocketConnected);
191+
}
192+
166193
await testdriver.auth();
167194
await testdriver.connect();
168195
console.log('[testdriver] ✅ Connected to sandbox');
169196

197+
if (debugConsoleSpy) {
198+
console.log('[DEBUG] After connect - sandbox.instanceSocketConnected:', testdriver.sandbox?.instanceSocketConnected);
199+
console.log('[DEBUG] After connect - sandbox.send:', typeof testdriver.sandbox?.send);
200+
}
201+
170202
// Set up console spy using vi.spyOn (test-isolated)
171203
setupConsoleSpy(testdriver, context.task.id);
172204

@@ -185,19 +217,9 @@ export function TestDriver(context, options = {}) {
185217

186218
// Add automatic log tracking when dashcam starts
187219
// Store original start method
188-
const originalDashcamStart = testdriver.dashcam.start.bind(testdriver.dashcam);
189-
testdriver.dashcam.start = async function() {
190-
// Call original start (which handles auth)
191-
await originalDashcamStart();
192-
193-
// Add log file tracking after dashcam starts
194-
try {
195-
await testdriver.dashcam.addFileLog(logPath, "TestDriver Log");
196-
console.log('[testdriver] ✅ Added log file to dashcam tracking');
197-
} catch (error) {
198-
console.warn('[testdriver] ⚠️ Failed to add log tracking:', error.message);
199-
}
200-
};
220+
221+
await testdriver.dashcam.addFileLog(logPath, "TestDriver Log");
222+
201223
} catch (error) {
202224
console.error('[testdriver] Error during setup:', error);
203225
throw error;

test-results/junit.xml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<testsuites name="vitest tests" tests="2" failures="0" errors="0" time="60.603655375">
3-
<testsuite name="testdriver/acceptance-sdk/assert.test.mjs" timestamp="2025-12-02T17:14:16.876Z" hostname="MacBookPro.lan" tests="2" failures="0" errors="0" skipped="0" time="60.603655375">
4-
<testcase classname="testdriver/acceptance-sdk/assert.test.mjs" name="Assert Test &gt; should assert the testdriver login page shows" time="60.60278825">
5-
</testcase>
6-
<testcase classname="testdriver/acceptance-sdk/assert.test.mjs" name="Assert Test &gt; should assert the testdriver login page shows 2" time="60.525202958">
2+
<testsuites name="vitest tests" tests="1" failures="0" errors="0" time="42.282716667">
3+
<testsuite name="testdriver/acceptance-sdk/assert.test.mjs" timestamp="2025-12-02T17:46:27.868Z" hostname="MacBookPro.lan" tests="1" failures="0" errors="0" skipped="0" time="42.282716667">
4+
<testcase classname="testdriver/acceptance-sdk/assert.test.mjs" name="Assert Test &gt; should assert the testdriver login page shows" time="42.281644625">
75
<system-out>
86
[testdriver] Connecting to sandbox...
9-
[testdriver] Connecting to sandbox...
107

118
[2m--`new` flag detected, will create a new sandbox[22m
129
[2mestablishing connection...[22m
1310

14-
[2m--`new` flag detected, will create a new sandbox[22m
15-
[2mestablishing connection...[22m
16-
17-
[2mauthenticating...[22m
18-
1911
[2mauthenticating...[22m
2012

2113
[2mcreating new sandbox...[22m
2214

23-
[2mcreating new sandbox...[22m
24-
2515
[2mconnecting...[22m
2616

2717
renderSandbox {
28-
sandboxId: [32m&apos;ibqy5ssepmmy4b8rq9uj0&apos;[39m,
29-
url: [32m&apos;https://6080-ibqy5ssepmmy4b8rq9uj0.e2b.app/vnc_lite.html?autoconnect=true&amp;resize=scale&apos;[39m
18+
sandboxId: [32m&apos;i1h8efg8w3ysbifg04xy8&apos;[39m,
19+
url: [32m&apos;https://6080-i1h8efg8w3ysbifg04xy8.e2b.app/vnc_lite.html?autoconnect=true&amp;resize=scale&apos;[39m
3020
}
3121

32-
[2mconnecting...[22m
33-
34-
renderSandbox {
35-
sandboxId: [32m&apos;iqs947t0rbtqi5t1h4y2u&apos;[39m,
36-
url: [32m&apos;https://6080-iqs947t0rbtqi5t1h4y2u.e2b.app/vnc_lite.html?autoconnect=true&amp;resize=scale&apos;[39m
37-
}
22+
Live test execution:
23+
http://localhost:49651?data=eyJyZXNvbHV0aW9uIjpbMTM2Niw3NjhdLCJ1cmwiOiJodHRwczovLzYwODAtaTFoOGVmZzh3M3lzYmlmZzA0eHk4LmUyYi5hcHAvdm5jX2xpdGUuaHRtbD9hdXRvY29ubmVjdD10cnVlJnJlc2l6ZT1zY2FsZSIsInRva2VuIjoiVjNiOHdHOSJ9
3824

3925
Running lifecycle: provision
4026
No currentFilePath found, using fallback: /Users/ianjennings/Development/cli/testdriver/testdriver.yaml

testdriver/acceptance-sdk/assert.test.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ describe("Assert Test", () => {
2222

2323
expect(result).toBeTruthy();
2424
});
25-
it("should assert the testdriver login page shows 2", async (context) => {
26-
const testdriver = TestDriver(context, { newSandbox: true });
25+
// it("should assert the testdriver login page shows 2", async (context) => {
26+
// const testdriver = TestDriver(context, { newSandbox: true });
2727

28-
// provision.chrome() automatically calls ready() and starts dashcam
29-
await testdriver.provision.chrome({
30-
url: 'http://testdriver-sandbox.vercel.app/login',
31-
});
28+
// // provision.chrome() automatically calls ready() and starts dashcam
29+
// await testdriver.provision.chrome({
30+
// url: 'http://testdriver-sandbox.vercel.app/login',
31+
// });
3232

33-
// Assert the TestDriver.ai Sandbox login page is displayed
34-
const result = await testdriver.assert(
35-
"the TestDriver.ai Sandbox login page is displayed",
36-
);
33+
// // Assert the TestDriver.ai Sandbox login page is displayed
34+
// const result = await testdriver.assert(
35+
// "the TestDriver.ai Sandbox login page is displayed",
36+
// );
3737

38-
expect(result).toBeTruthy();
39-
});
38+
// expect(result).toBeTruthy();
39+
// });
4040
});
4141

0 commit comments

Comments
 (0)