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
5 changes: 5 additions & 0 deletions data/input/user-rules.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
! Title: Custom User Rules
! Description: Personal ad-blocking rules
! Last modified: 2024-01-01
||example-ads.com^
||tracking.example.net^
10 changes: 2 additions & 8 deletions src/rules-compiler-typescript/compiler-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
"sources": [
{
"name": "User Rules",
"type": "inline",
"content": [
"! Title: Custom User Rules",
"! Description: Personal ad-blocking rules",
"! Last modified: 2024-01-01",
"||example-ads.com^",
"||tracking.example.net^"
]
"source": "data/input/user-rules.txt",
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file path referenced in the configuration will not resolve correctly. The compiler runs from the src/rules-compiler-typescript/ directory (as shown in CI workflows), so data/input/user-rules.txt will resolve to src/rules-compiler-typescript/data/input/user-rules.txt, but the actual file was created at data/input/user-rules.txt (repository root).

The path should be ../../data/input/user-rules.txt to correctly reference the file at the repository root from the compiler's working directory.

Copilot uses AI. Check for mistakes.
"type": "adblock"
}
],
"transformations": [
Expand Down
2 changes: 1 addition & 1 deletion src/rules-compiler-typescript/src/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Deno.test('validateConfiguration - validates source objects', () => {
const result = validateConfiguration(config);

assertEquals(result.valid, false);
assertEquals(result.errors.some((e) => e.includes('sources[0]') && (e.includes('source') || e.includes('content'))), true);
assertEquals(result.errors.some((e) => e.includes('sources[0]') && e.includes('source')), true);
});

Deno.test('validateConfiguration - validates source type values', () => {
Expand Down
41 changes: 10 additions & 31 deletions src/rules-compiler-typescript/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,42 +63,21 @@ function validateSource(source: unknown, index: number): string[] {

const sourceObj = source as Record<string, unknown>;

// Either 'source' or 'content' field is required
const hasSource = sourceObj['source'] && typeof sourceObj['source'] === 'string';
const hasContent = sourceObj['content'] && Array.isArray(sourceObj['content']);

if (!hasSource && !hasContent) {
errors.push(`${prefix}: must have either 'source' (URL/path) or 'content' (inline rules) field`);
}

// Validate source field if present
if (sourceObj['source'] !== undefined) {
if (typeof sourceObj['source'] !== 'string') {
errors.push(`${prefix}.source: must be a string`);
} else if (sourceObj['source'].trim() === '') {
errors.push(`${prefix}.source: cannot be empty`);
}
}

// Validate content field if present
if (sourceObj['content'] !== undefined) {
if (!Array.isArray(sourceObj['content'])) {
errors.push(`${prefix}.content: must be an array`);
} else {
for (let i = 0; i < sourceObj['content'].length; i++) {
if (typeof sourceObj['content'][i] !== 'string') {
errors.push(`${prefix}.content[${i}]: must be a string`);
}
}
}
// Required field: 'source' (path or URL)
if (!sourceObj['source']) {
errors.push(`${prefix}: must have 'source' field (URL or file path)`);
} else if (typeof sourceObj['source'] !== 'string') {
errors.push(`${prefix}.source: must be a string`);
} else if (sourceObj['source'].trim() === '') {
errors.push(`${prefix}.source: cannot be empty`);
}

// type validation if present
// type validation if present - only 'adblock' or 'hosts' allowed per upstream schema
if (sourceObj['type'] !== undefined) {
if (typeof sourceObj['type'] !== 'string') {
errors.push(`${prefix}.type: must be a string`);
} else if (!['adblock', 'hosts', 'inline'].includes(sourceObj['type'])) {
errors.push(`${prefix}.type: must be 'adblock', 'hosts', or 'inline'`);
} else if (!['adblock', 'hosts'].includes(sourceObj['type'])) {
errors.push(`${prefix}.type: must be 'adblock' or 'hosts'`);
}
}

Expand Down
Loading