Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions client/main/conversation/goal-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ function runtimeRefs(file, source) {
}
}
if (ext === '.css') {
const css = /(?:url|@import)\s*\(\s*(["']?)(.*?)\1\s*\)|@import\s+(["'])(.*?)\3/gi;
let match = css.exec(source);
while (match) {
push(match[2] || match[4], 'style');
match = css.exec(source);
}
for (const value of require('./stylesheet-references').references(source)) push(value, 'style');
}
if (['.html', '.htm', '.js', '.mjs', '.cjs'].includes(ext)) {
const moduleRef = /(?:from\s*|import\s*\(\s*)(["'])(.*?)\1/gi;
Expand Down
43 changes: 43 additions & 0 deletions client/tests/goal-stylesheet-references.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';
const test = require('node:test'), assert = require('node:assert/strict');
const fs = require('node:fs'), os = require('node:os'), path = require('node:path');
const verifier = require('../main/conversation/goal-verifier');

function site(t, css, files = {}) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'soduwork-goal-css-'));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
fs.writeFileSync(path.join(root, 'index.html'), '<link rel="stylesheet" href="style.css"><h1>Fixture</h1>');
fs.writeFileSync(path.join(root, 'style.css'), css);
for (const [name, text] of Object.entries(files)) fs.writeFileSync(path.join(root, name), text);
return verifier.websiteProbe(root, { path: path.join(root, 'index.html') }, {}, {});
}

test('website goal verification ignores URLs inside CSS strings and comments', t => {
for (const css of ['body::after{content:"url(missing.png)"}',
'/* url(missing.png) @import "missing.css"; */ body{color:red}']) {
assert.equal(site(t, css).pass, true);
}
});

test('website goal verification rejects a missing import after CSS comments', t => {
const result = site(t, '@import /* annotation */ "missing.css"; body{color:red}');
assert.equal(result.pass, false);
assert.match(result.gaps.join('\n'), /missing\.css/);
});

test('website goal verification follows comment-separated imports to missing nested assets', t => {
const result = site(t, '@import /* annotation */ "theme.css";',
{ 'theme.css': 'body{background:url("missing.png")}' });
assert.equal(result.pass, false);
assert.match(result.gaps.join('\n'), /missing\.png/);
});

test('website goal verification resolves escaped CSS paths with the original file spelling', t => {
assert.equal(site(t, 'body{background:url("icon\\20 1.svg")}',
{ 'icon 1.svg': '<svg xmlns="http://www.w3.org/2000/svg"></svg>' }).pass, true);
});

test('website goal verification still rejects actual missing and undeclared remote CSS resources', t => {
assert.equal(site(t, 'body{background:url("missing.png")}').pass, false);
assert.equal(site(t, 'body{background:url("https://fixture.invalid/image.png")}').pass, false);
});
Loading