-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.js
More file actions
205 lines (183 loc) · 5.81 KB
/
verify.js
File metadata and controls
205 lines (183 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env node
/**
* Manual verification script for Web Reader.
*
* Tests real websites to confirm the cascade engine works.
* NOT for CI — these hit live sites and can be flaky due to
* network conditions, rate limits, or site changes.
*
* Usage:
* node verify.js # Run all checks
* node verify.js --quick # Skip slow browser tests
* node verify.js reddit # Run one specific check
*/
const { cascade, handlers, tryDefuddle, fetchWithBrowser } = require('./skills/web-reader/render.js');
const fs = require('fs');
const path = require('path');
const os = require('os');
const CHECKS = [
{
name: 'Wikipedia',
url: 'https://en.wikipedia.org/wiki/Turing_machine',
layer: 'handler',
expect: (text) => text.includes('Turing') && text.length > 500,
},
{
name: 'GitHub repo',
url: 'https://github.com/anthropics/claude-code',
layer: 'handler',
expect: (text) => text.includes('claude') || text.includes('Claude') || text.includes('anthropic'),
},
{
name: 'GitHub issue',
url: 'https://github.com/anthropics/claude-code/issues/1',
layer: 'handler',
expect: (text) => text.includes('#1') && text.length > 100,
},
{
name: 'Reddit subreddit',
url: 'https://www.reddit.com/r/programming/',
layer: 'handler',
expect: (text) => text.includes('Score:') && text.length > 200,
},
{
name: 'Reddit post',
url: 'https://www.reddit.com/r/programming/top/.json?limit=1',
layer: 'handler',
expect: (text) => text.length > 100,
transform: (url) => 'https://www.reddit.com/r/programming/top/?limit=1',
},
{
name: 'Hacker News',
url: 'https://news.ycombinator.com/item?id=1',
layer: 'handler',
expect: (text) => text.includes('Y Combinator') || text.includes('Score:'),
},
{
name: 'Defuddle (docs)',
url: 'https://docs.github.com/en/get-started',
layer: 'defuddle',
expect: (text) => text && text.length > 200,
slow: false,
},
{
name: 'SPA (coachsensai.com)',
url: 'https://www.coachsensai.com/',
layer: 'browser',
expect: (text) => text && text.length > 200,
slow: true,
},
{
name: 'LinkedIn job posting',
url: 'https://www.linkedin.com/jobs/view/4196024795',
layer: 'browser',
expect: (text) => text && text.length > 200,
slow: true,
},
{
name: 'Crates.io (SPA)',
url: 'https://crates.io/crates/serde',
layer: 'browser',
expect: (text) => text && (text.includes('serde') || text.includes('Serde')) && text.length > 200,
slow: true,
},
];
const COLORS = {
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
dim: '\x1b[2m',
reset: '\x1b[0m',
bold: '\x1b[1m',
};
function formatTime(ms) {
if (ms < 1000) return ms + 'ms';
return (ms / 1000).toFixed(1) + 's';
}
async function runCheck(check) {
const url = check.transform ? check.transform(check.url) : check.url;
const start = Date.now();
// Use a temp domains file so verification doesn't pollute the real one
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'wr-verify-'));
const tmpDomains = path.join(tmpDir, 'domains.json');
try {
const { result, method } = await cascade(url, { domainsFile: tmpDomains });
const elapsed = Date.now() - start;
if (!result) {
return { pass: false, time: elapsed, error: 'No content returned', method: null };
}
const valid = check.expect(result);
if (!valid) {
return {
pass: false,
time: elapsed,
error: 'Content did not match expectations (' + result.length + ' chars)',
method,
};
}
return { pass: true, time: elapsed, method, chars: result.length };
} catch (e) {
return { pass: false, time: Date.now() - start, error: e.message, method: null };
} finally {
try { fs.rmSync(tmpDir, { recursive: true }); } catch {}
}
}
async function main() {
const args = process.argv.slice(2);
const quick = args.includes('--quick');
const filter = args.find(a => !a.startsWith('--'));
let checks = CHECKS;
if (filter) {
checks = CHECKS.filter(c => c.name.toLowerCase().includes(filter.toLowerCase()));
if (checks.length === 0) {
console.error('No checks match "' + filter + '". Available:');
CHECKS.forEach(c => console.error(' ' + c.name));
process.exit(1);
}
}
if (quick) {
checks = checks.filter(c => !c.slow);
}
console.log('');
console.log(COLORS.bold + 'Web Reader Verification' + COLORS.reset);
console.log(COLORS.dim + 'Testing ' + checks.length + ' sites against live endpoints' + COLORS.reset);
console.log('');
let passed = 0;
let failed = 0;
for (const check of checks) {
process.stdout.write(' ' + check.name.padEnd(28) + COLORS.dim + check.layer.padEnd(10) + COLORS.reset);
const result = await runCheck(check);
if (result.pass) {
passed++;
console.log(
COLORS.green + 'PASS' + COLORS.reset +
COLORS.dim + ' ' + formatTime(result.time).padStart(6) +
' ' + result.method +
' (' + result.chars + ' chars)' + COLORS.reset
);
} else {
failed++;
console.log(
COLORS.red + 'FAIL' + COLORS.reset +
COLORS.dim + ' ' + formatTime(result.time).padStart(6) +
' ' + result.error + COLORS.reset
);
}
}
console.log('');
console.log(
COLORS.bold +
passed + ' passed' +
(failed > 0 ? ', ' + COLORS.red + failed + ' failed' + COLORS.reset : '') +
COLORS.reset +
COLORS.dim + ' out of ' + checks.length + ' checks' + COLORS.reset
);
console.log('');
if (failed > 0) {
console.log(COLORS.yellow + 'Note: Failures may be caused by network conditions, rate limits,' + COLORS.reset);
console.log(COLORS.yellow + 'or site changes. Re-run individual checks to confirm.' + COLORS.reset);
console.log('');
}
process.exit(failed > 0 ? 1 : 0);
}
main();