// SPDX-License-Identifier: AGPL-3.0-only 'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const path = require('node:path'); const core = require('../../src/core'); test('requires Beta 2 feature and ABI', () => { assert.equal(core.validateVersion({compiler: 'v1.0.0-beta.2', runtime_abi: 'sando.v1', features: ['lsp-stdio']}), ''); assert.match(core.validateVersion({compiler: 'v1.0.0-beta.1', runtime_abi: 'sando.v1', features: []}), /beta\.2/); assert.match(core.validateVersion({compiler: 'v1.0.0-beta.2', runtime_abi: 'wrong', features: ['lsp-stdio']}), /ABI/); assert.match(core.validateVersion({compiler: 'v1.0.0-beta.2', runtime_abi: 'sando.v1', features: []}), /lsp-stdio/); }); test('requires configured executable to be absolute', () => { assert.equal(core.resolveExecutable(''), 'himesan'); assert.throws(() => core.resolveExecutable('bin/himesan'), /absolute/); const absolute = path.resolve('bin/himesan'); assert.equal(core.resolveExecutable(absolute), path.normalize(absolute)); }); test('selects active workspace and refuses ambiguous fallback', () => { const folders = [{uri: 'file:///one', name: 'one'}, {uri: 'file:///two', name: 'two'}]; assert.equal(core.selectWorkspace(folders, 'file:///two/views/home.sando').name, 'two'); assert.equal(core.selectWorkspace(folders, ''), null); assert.equal(core.selectWorkspace([folders[0]], '').name, 'one'); }); test('installation guidance is pinned and runtime-first', () => { const guidance = core.installationGuidance(); assert.ok(guidance.indexOf('sando@v1.0.0-beta.1') < guidance.indexOf('himesan@v1.0.0-beta.2')); assert.equal(guidance.includes('@latest'), false); }); test('workspace trust is a hard executable boundary', () => { assert.equal(core.canExecute(true), true); assert.equal(core.canExecute(false), false); assert.equal(core.canExecute(undefined), false); }); test('workspace files cannot add executable roots outside their directory tree', () => { const workspace = {scheme: 'file', fsPath: path.resolve('trusted', 'project.code-workspace')}; assert.equal(core.isTrustedWorkspaceFolder({fsPath: path.resolve('trusted', 'one')}, workspace), true); assert.equal(core.isTrustedWorkspaceFolder({fsPath: path.resolve('elsewhere')}, workspace), false); assert.equal(core.isTrustedWorkspaceFolder({fsPath: path.resolve('trusted', 'one')}, undefined), true); }); test('process runner reports failure and cancellation without a shell', async () => { const failure = await core.runProcess(process.execPath, ['-e', 'process.exit(7)'], {timeout: 5000}); assert.equal(failure.code, 7); let cancel; const token = {onCancellationRequested(callback) { cancel = callback; return {dispose() {}}; }}; const running = core.runProcess(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], {timeout: 5000, token}); cancel(); await assert.rejects(running, /canceled/); });