this repo has no description
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <title>OHC JTW Integration Test</title>
6</head>
7<body>
8 <h1>OHC JTW Integration Test</h1>
9 <div id="status">Loading...</div>
10 <div id="results"></div>
11 <script type="module">
12 import { OcamlWorker } from '/client/ocaml-worker.js';
13
14 const status = document.getElementById('status');
15 const results = document.getElementById('results');
16
17 function log(msg) {
18 const p = document.createElement('pre');
19 p.textContent = msg;
20 results.appendChild(p);
21 console.log(msg);
22 }
23
24 // Read config from URL params
25 const params = new URLSearchParams(window.location.search);
26 const universe = params.get('universe');
27 const compilerVersion = params.get('compiler') || '5.4.0';
28
29 if (!universe) {
30 status.textContent = 'Error: ?universe= parameter required';
31 throw new Error('universe parameter required');
32 }
33
34 status.textContent = 'Fetching findlib_index.json...';
35 const indexUrl = `/jtw-output/u/${universe}/findlib_index.json`;
36 const { worker, stdlib_dcs, findlib_index } = await OcamlWorker.fromIndex(
37 indexUrl, '/jtw-output', { timeout: 120000 });
38
39 try {
40 status.textContent = 'Initializing (loading stdlib)...';
41 await worker.init({
42 findlib_requires: [],
43 stdlib_dcs: stdlib_dcs,
44 findlib_index: findlib_index,
45 });
46
47 status.textContent = 'Worker ready';
48 document.getElementById('status').dataset.ready = 'true';
49
50 // Test 1: Basic arithmetic
51 log('--- Test 1: Basic arithmetic ---');
52 const r1 = await worker.eval('let x = 1 + 2;;');
53 log('eval: let x = 1 + 2;;');
54 log('caml_ppf: ' + r1.caml_ppf);
55 document.getElementById('results').dataset.test1 = r1.caml_ppf;
56
57 // Test 2: String operations
58 log('--- Test 2: String operations ---');
59 const r2 = await worker.eval('String.concat ", " ["hello"; "world"];;');
60 log('eval: String.concat ", " ["hello"; "world"];;');
61 log('caml_ppf: ' + r2.caml_ppf);
62 document.getElementById('results').dataset.test2 = r2.caml_ppf;
63
64 // Test 3: Load fmt via #require
65 log('--- Test 3: Load fmt ---');
66 const r3 = await worker.eval('#require "fmt";;');
67 log('eval: #require "fmt";;');
68 log('caml_ppf: ' + r3.caml_ppf);
69 log('stderr: ' + r3.stderr);
70 document.getElementById('results').dataset.test3 = 'loaded';
71
72 // Test 4: Use fmt
73 log('--- Test 4: Use Fmt ---');
74 const r4 = await worker.eval('Fmt.str "%a" Fmt.int 42;;');
75 log('eval: Fmt.str "%a" Fmt.int 42;;');
76 log('caml_ppf: ' + r4.caml_ppf);
77 document.getElementById('results').dataset.test4 = r4.caml_ppf;
78
79 // Test 5: Completions
80 log('--- Test 5: Completions ---');
81 const r5 = await worker.complete('Fmt.i', 5);
82 log('complete: Fmt.i at pos 5');
83 const entries = r5.completions?.entries || [];
84 log('entries: ' + entries.map(e => e.name).join(', '));
85 document.getElementById('results').dataset.test5 = entries.length > 0 ? 'ok' : 'empty';
86
87 status.textContent = 'All tests complete';
88 document.getElementById('status').dataset.done = 'true';
89
90 } catch (err) {
91 status.textContent = 'Error: ' + err.message;
92 log('ERROR: ' + err.message);
93 log('Stack: ' + err.stack);
94 document.getElementById('status').dataset.error = err.message;
95 }
96 </script>
97</body>
98</html>