mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
64 lines
4.2 KiB
JavaScript
64 lines
4.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {readFileSync,existsSync,mkdtempSync,rmSync,mkdirSync,copyFileSync,writeFileSync} from 'node:fs';
|
|
import {dirname,resolve,join} from 'node:path';
|
|
import {tmpdir} from 'node:os';
|
|
import {fileURLToPath} from 'node:url';
|
|
import {spawnSync} from 'node:child_process';
|
|
const root=resolve(dirname(fileURLToPath(import.meta.url)),'..');
|
|
const manifest=JSON.parse(readFileSync(join(root,'release/manifest.json')));
|
|
test('release versions and publishable Rust dependency closure agree',()=>{
|
|
assert.match(manifest.version,/^\d+\.\d+\.\d+-beta\.\d+$/);
|
|
assert.ok(readFileSync(join(root,'Cargo.toml'),'utf8').includes(`version = "${manifest.version}"`));
|
|
for(const pkg of manifest.rustPackages) {
|
|
const cargo=readFileSync(join(root,pkg.directory,'Cargo.toml'),'utf8');
|
|
assert.ok(cargo.includes('version.workspace = true'));assert.ok(cargo.includes('publish = ["crates-io"]'));
|
|
for(const line of cargo.split('\n').filter(l=>l.includes('{')&&l.includes('path =')))assert.ok(line.includes(`version = "=${manifest.version}"`),line);
|
|
assert.ok(existsSync(join(root,pkg.directory,'LICENSE')));
|
|
}
|
|
for(const folder of ['typescript-sdk','desktop-starters'])assert.equal(JSON.parse(readFileSync(join(root,folder,'package.json'))).version,manifest.version);
|
|
// Skill compatibility is pinned/tested by its standalone package tests. Its
|
|
// published consumer SDK may differ from this native-release source manifest.
|
|
assert.ok(readFileSync(join(root,'typescript-sdk/src/version.ts'),'utf8').includes(JSON.stringify(manifest.version)));
|
|
assert.equal(new Set(manifest.targets.map(t=>t.rust)).size,manifest.targets.length);
|
|
});
|
|
test('source-mode starter keeps explicit checkout references',()=>{
|
|
const dir=mkdtempSync(join(tmpdir(),'ow-source-starter-'));
|
|
try {
|
|
const result=spawnSync(process.execPath,[join(root,'desktop-starters/create.mjs'),join(dir,'app'),'--sdk-root',root],{encoding:'utf8'});
|
|
assert.equal(result.status,0,result.stderr);
|
|
assert.equal(JSON.parse(readFileSync(join(dir,'app/package.json'))).dependencies['@openworkerai/harness-sdk'],'file:'+join(root,'typescript-sdk'));
|
|
}finally{rmSync(dir,{recursive:true,force:true});}
|
|
});
|
|
test('registry-mode starters require no checkout paths',()=>{
|
|
const dir=mkdtempSync(join(tmpdir(),'ow-registry-starter-'));
|
|
try {for(const template of ['electron-game-builder','tauri-game-builder']) {
|
|
const dest=join(dir,template);const result=spawnSync(process.execPath,[join(root,'desktop-starters/create.mjs'),dest,'--template',template],{encoding:'utf8'});
|
|
assert.equal(result.status,0,result.stderr);const config=JSON.parse(readFileSync(join(dest,'openworker.json')));assert.equal(config.sdkRoot,null);
|
|
const pkg=JSON.parse(readFileSync(join(dest,'package.json')));assert.equal((pkg.dependencies['@openworkerai/harness-sdk']??pkg.devDependencies['@openworkerai/harness-sdk']),manifest.version);
|
|
if(template.startsWith('tauri'))assert.ok(readFileSync(join(dest,'src-tauri/Cargo.toml'),'utf8').includes(`openworker-sdk = "=${manifest.version}"`));
|
|
}}finally{rmSync(dir,{recursive:true,force:true});}
|
|
});
|
|
|
|
test('Markdown programs are identical in LF and Windows CRLF checkouts',()=>{
|
|
const dir=mkdtempSync(join(tmpdir(),'ow-guide-line-endings-'));
|
|
try {
|
|
const script=join(dir,'harness/release/check-examples.mjs');
|
|
const guide=join(dir,'docs/harness/guides/desktop.md');
|
|
mkdirSync(dirname(script),{recursive:true});mkdirSync(dirname(guide),{recursive:true});
|
|
copyFileSync(join(root,'release/check-examples.mjs'),script);
|
|
const source=readFileSync(join(root,'../docs/harness/guides/desktop.md'),'utf8').replace(/\r\n/g,'\n');
|
|
const programs=[];
|
|
for(const [name,newline] of [['lf','\n'],['crlf','\r\n']]) {
|
|
writeFileSync(guide,source.replace(/\n/g,newline));
|
|
const output=join(dir,name);
|
|
const result=spawnSync(process.execPath,[script,output],{encoding:'utf8'});
|
|
assert.equal(result.status,0,result.stderr);
|
|
programs.push(['desktop.ts','desktop.rs'].map(file=>readFileSync(join(output,file),'utf8')));
|
|
}
|
|
assert.deepEqual(programs[1],programs[0]);
|
|
assert.match(programs[0][0],/@openworkerai\/harness-sdk/);
|
|
assert.match(programs[0][1],/use openworker_sdk/);
|
|
}finally{rmSync(dir,{recursive:true,force:true});}
|
|
});
|