mirror of
https://github.com/citeworthyio/seo-agent.git
synced 2026-08-11 13:22:39 +02:00
missing_og_image gets its fix path: an og_image override the injector serves as BOTH og:image and twitter:image, rewrite-or-insert per tag with independent presence flags. Unlike canonical there is no computable answer — the value is CHOSEN (a host UI offers the site's own images) and rides createProposal, never the drafting queue: fieldForRule stays null for the rule, draftAndCreate refuses the field outright, and a model can never invent an image URL. invalidOgImageReason is the one gate (createProposal, applyOverride fail-closed, and the injector belt) — the canonical validator's sibling that deliberately allows query strings (CDN sizing params) and foreign http(s) hosts. createProposal gains an optional findingId so a host-created proposal carries the same remediation chip linkage as a drafted one. verify.ts checks stored og_image against the crawl. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
363 lines
17 KiB
TypeScript
363 lines
17 KiB
TypeScript
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import worker from '../injector/src/index';
|
|
import { invalidCanonicalReason, storedOverrideValue, applyOverride, OVERRIDE_FIELDS } from '../src/overrides';
|
|
import { expectedCanonicalUrl } from '../src/rules';
|
|
import { fieldForRule, draftAndCreate, CANONICAL_RULES, currentValueFor } from '../src/propose';
|
|
import { createProposal } from '../src/actions';
|
|
import { verifyOverrides } from '../src/verify';
|
|
import { resolveSiteConfig } from '../src/config';
|
|
|
|
// The canonical lane, end to end at the unit level: the validator that gates
|
|
// every path to KV, the deterministic drafter (no model call, ever), the
|
|
// verify sense, and the injector's rewrite-or-insert behaviour.
|
|
|
|
const config = resolveSiteConfig({ SITE_URL: 'https://example.com', SITE_NAME: 'Acme' });
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// invalidCanonicalReason — the one gate (storedOverrideValue and the drafter
|
|
// both run it, and the injector's serve-time belt enforces the same character
|
|
// rules).
|
|
// ---------------------------------------------------------------------------
|
|
|
|
describe('invalidCanonicalReason', () => {
|
|
it('accepts a clean absolute https URL, and a bare-origin homepage form', () => {
|
|
expect(invalidCanonicalReason('https://example.com/pricing')).toBeNull();
|
|
expect(invalidCanonicalReason('https://example.com')).toBeNull();
|
|
expect(invalidCanonicalReason('http://example.com/a')).toBeNull();
|
|
});
|
|
|
|
it('rejects the shapes that are not a page name', () => {
|
|
expect(invalidCanonicalReason('')).toMatch(/empty/);
|
|
expect(invalidCanonicalReason('/pricing')).toMatch(/absolute/);
|
|
expect(invalidCanonicalReason('javascript:alert(1)')).toMatch(/http/);
|
|
expect(invalidCanonicalReason('https://example.com/a?utm=1')).toMatch(/query/);
|
|
expect(invalidCanonicalReason('https://example.com/a#frag')).toMatch(/fragment/);
|
|
});
|
|
|
|
it('rejects every character that could escape an href attribute', () => {
|
|
for (const bad of ['https://example.com/a b', 'https://example.com/a"', "https://example.com/a'", 'https://example.com/<a', 'https://example.com/a\\b', 'https://example.com/a |