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
4 changes: 3 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"audit:nattzy-cta": "node scripts/check-nattzy-cta.mjs",
"test:nattzy-cta": "node --test scripts/check-nattzy-cta.test.mjs",
"audit:nattzy-timezone": "node scripts/check-nattzy-cta.mjs --timezone",
"test:workdays-faq": "node --test scripts/workdays-faq-parity.test.mjs"
"test:workdays-faq": "node --test scripts/workdays-faq-parity.test.mjs",
"audit:live-workdays-exclusive": "node scripts/check-live-workdays-exclusive.mjs",
"test:live-workdays-exclusive": "node --test scripts/check-live-workdays-exclusive.test.mjs"
},
"dependencies": {
"@types/qrcode": "^1.5.6",
Expand Down
95 changes: 95 additions & 0 deletions site/scripts/check-live-workdays-exclusive.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env node
/**
* Public, read-only release proof for the new inclusive/exclusive Workdays UX.
* Merging source files is not proof the content is actually served.
* Usage: node scripts/check-live-workdays-exclusive.mjs [https://toolify365.com]
*/
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";

export const TARGETS = [
{ locale:"en", label:"Exclude start and end dates", mode:"N workdays from a date", faq:"not always 2" },
{ locale:"ja", label:"開始日・終了日を除いて数える", mode:"○営業日後の日付", faq:"一律に2日" },
{ locale:"es", label:"Excluir fechas inicial y final", mode:"N días hábiles desde una fecha", faq:"no siempre 2" },
{ locale:"ar", label:"استبعاد تاريخي البداية والنهاية", mode:"N يوم عمل بعد تاريخ", faq:"ولا تطرح 2" },
];

export function attr(tag, name) {
const match = [...tag.matchAll(/\b([A-Za-z_:][-A-Za-z0-9_:]*)\s*=\s*(["'])(.*?)\2/gs)]
.find(m => m[1].toLowerCase() === name.toLowerCase());
return match?.[3] ?? "";
}

export function visibleText(html) {
const text = html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"")
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"")
.replace(/<!--[\s\S]*?-->/g,"")
.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i)?.[1] ?? "";
return text.replace(/<[^>]+>/g," ")
.replace(/&amp;/gi,"&").replace(/&lt;/gi,"<").replace(/&gt;/gi,">")
.replace(/&quot;/gi,'"').replace(/&#(?:39|x27);/gi,"'")
.replace(/\s+/g," ").trim();
}

export function inspectWorkdaysHtml(html, item, origin="https://toolify365.com") {
const errors = [];
const path = "/" + item.locale + "/tools/workdays-calculator";
const body = visibleText(html);
if (!body) errors.push("VISIBLE_BODY_MISSING");
// A mention in FAQ text alone must not masquerade as a real checkbox.
const markup=html.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"")
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi,"")
.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i)?.[1] ?? "";
const checkboxLabel=[...markup.matchAll(/<label\b[^>]*>([\s\S]*?)<\/label>/gi)]
.some(m=>/<input\b[^>]*type=(["'])checkbox\1/i.test(m[1]) && m[1].includes(item.label));
if(!checkboxLabel) errors.push("CHECKBOX_CONTROL_NOT_RENDERED");
for (const [code,phrase] of [
["NEW_CHECKBOX_NOT_VISIBLE",item.label],
["EXISTING_ADD_MODE_NOT_VISIBLE",item.mode],
["CORRECTED_BOUNDARY_FAQ_NOT_VISIBLE",item.faq],
]) if (!body.includes(phrase)) errors.push(code);
const htmlTag=html.match(/<html\b[^>]*>/i)?.[0] ?? "";
if (attr(htmlTag,"lang").toLowerCase()!==item.locale.toLowerCase()) errors.push("WRONG_HTML_LANG");
const canonicalTags=[...html.matchAll(/<link\b[^>]*>/gi)].map(m=>m[0]).filter(tag=>attr(tag,"rel").toLowerCase()==="canonical");
const canonical = attr(canonicalTags[0]??"","href");
try {
const value = new URL(canonical,origin);
if (canonicalTags.length!==1 || value.origin!==origin || value.pathname.replace(/\/$/,"")!==path)
errors.push("WRONG_CANONICAL");
} catch { errors.push("INVALID_CANONICAL"); }
const title=[...html.matchAll(/<title\b[^>]*>[\s\S]*?<\/title>/gi)];
if (title.length!==1) errors.push("TITLE_MISSING_OR_DUPLICATE");
if (item.locale==="en" || item.locale==="ja") {
const robots=[...html.matchAll(/<meta\b[^>]*>/gi)].map(m=>m[0]).filter(tag=>attr(tag,"name").toLowerCase()==="robots");
if (robots.some(tag=>/(?:^|[,;\s])noindex(?:$|[,;\s])/i.test(attr(tag,"content"))))
errors.push("INDEXABLE_LOCALE_UNEXPECTED_NOINDEX");
}
return {ok:errors.length===0,errors,canonical};
}

export async function run(url=process.argv[2]||"https://toolify365.com") {
const root=new URL(url);
if (root.pathname!=="/" || root.search || root.hash || root.username || root.password) throw Error("Origin only");
if (root.hostname!=="toolify365.com" && root.hostname!=="localhost") throw Error("Unexpected host");
if(root.protocol!=="https:" && root.hostname!=="localhost") throw Error("HTTPS is required");
const results=[];
for(const item of TARGETS){
const path="/" + item.locale + "/tools/workdays-calculator",url=root.origin+path;
try{
const response=await fetch(url,{redirect:"follow",headers:{"Cache-Control":"no-cache","User-Agent":"Toolify365WorkdayReleaseVerifier/1.0","Accept-Language":item.locale},signal:AbortSignal.timeout(16000)});
if(!response.ok)throw Error("HTTP "+response.status);
const actual=new URL(response.url);
if(actual.origin!==root.origin || actual.pathname.replace(/\/$/,"")!==path)throw Error("UNEXPECTED_REDIRECT: "+response.url);
const proof=inspectWorkdaysHtml(await response.text(),item,root.origin);
if ((item.locale==="en" || item.locale==="ja") && /\\bnoindex\\b/i.test(response.headers.get("x-robots-tag")||"")) {
proof.errors.push("INDEXABLE_LOCALE_HTTP_NOINDEX");
proof.ok=false;
}
results.push({url,status:response.status,...proof});
}catch(e){results.push({url,ok:false,errors:[e.message||String(e)]});}
}
console.log(JSON.stringify({checkedAt:new Date().toISOString(),kind:"read_only_public_release_proof",results},null,2));
if(results.some(x=>!x.ok))process.exitCode=1;
return results;
}
if (process.argv[1]&&resolve(process.argv[1])===fileURLToPath(import.meta.url)) run().catch(e=>{console.error(e);process.exitCode=1;});
38 changes: 38 additions & 0 deletions site/scripts/check-live-workdays-exclusive.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import test from "node:test";
import assert from "node:assert/strict";
import { TARGETS, inspectWorkdaysHtml, visibleText } from "./check-live-workdays-exclusive.mjs";

const fixture = item => '<!doctype html><html lang="'+item.locale+'"><head>'+
'<title>Workdays Calculator | Toolify365</title>'+
'<link href="https://toolify365.com/'+item.locale+'/tools/workdays-calculator" rel="canonical"></head>'+
'<body><main><button>'+item.mode+'</button><label><input type="checkbox"><span>'+item.label+'</span></label>'+
'<details><summary>FAQ</summary><p>'+item.faq+'</p></details></main></body></html>';

test("only four representative locales checked, index policy remains locale scoped",()=>{
assert.deepEqual(TARGETS.map(x=>x.locale),["en","ja","es","ar"]);
assert.equal(new Set(TARGETS.map(x=>x.locale)).size,4);
});
for(const item of TARGETS) {
test(item.locale+": rendered and canonical page accepted",()=>assert.equal(inspectWorkdaysHtml(fixture(item),item).ok,true));
test(item.locale+": stale FAQ or absent checkbox rejected",()=>{
const x=fixture(item);
assert.ok(inspectWorkdaysHtml(x.replace(item.faq,"old inaccurate advice"),item).errors.includes("CORRECTED_BOUNDARY_FAQ_NOT_VISIBLE"));
assert.ok(inspectWorkdaysHtml(x.replace(item.label,"missing label"),item).errors.includes("NEW_CHECKBOX_NOT_VISIBLE"));
assert.ok(inspectWorkdaysHtml(x.replace('<input type="checkbox">',''),item).errors.includes("CHECKBOX_CONTROL_NOT_RENDERED"));
assert.ok(inspectWorkdaysHtml(x.replace('rel="canonical"','rel="alternate"'),item).errors.includes("WRONG_CANONICAL"));
assert.ok(inspectWorkdaysHtml(x.replace('lang="'+item.locale+'"','lang="other"'),item).errors.includes("WRONG_HTML_LANG"));
});
}
test("script and style contents cannot spoof visible checkbox/FAQ",()=>{
const item=TARGETS[0],x=fixture(item);
const bad=x.replace('<span>'+item.label+'</span>','<span>old state</span>')
.replace('<p>'+item.faq+'</p>','<p>wrong FAQ</p>')
.replace('</body>','<script>'+item.label+item.faq+'</script><style>'+item.label+'</style></body>');
assert.ok(!visibleText(bad).includes(item.label));
assert.ok(inspectWorkdaysHtml(bad,item).errors.includes("NEW_CHECKBOX_NOT_VISIBLE"));
assert.ok(inspectWorkdaysHtml(bad,item).errors.includes("CORRECTED_BOUNDARY_FAQ_NOT_VISIBLE"));
});
test("noindex cannot pass for an index-eligible core locale",()=>{
const item=TARGETS[0],html=fixture(item).replace('</head>','<meta name="robots" content="noindex,follow"></head>');
assert.ok(inspectWorkdaysHtml(html,item).errors.includes("INDEXABLE_LOCALE_UNEXPECTED_NOINDEX"));
});
Loading