fix: relax Apec normalization failures

This commit is contained in:
Antoine 2026-06-03 22:24:11 +02:00
parent 40b3619578
commit a998f1d968
4 changed files with 11 additions and 23 deletions

View File

@ -213,19 +213,9 @@ class ApecAdapter:
"""
() => {
const title = document.querySelector('.container-details-offer h1, h1');
const companySelectors = [
'.card-ents .ents-name',
'.card-ents-quote',
'.details-offer-list li:first-of-type',
];
const company = companySelectors
.map((selector) => document.querySelector(selector))
.find((element) => (element?.textContent || '').trim().length > 0);
const reference = document.querySelector('.ref-offre');
const offerList = document.querySelector('.details-offer-list');
const descriptionReady = Array.from(document.querySelectorAll('.details-post h4')).some((heading) => {
return (heading.textContent || '').trim() === 'Descriptif du poste';
});
return !!title && !!offerList && !!company && (company.textContent || '').trim().length > 0 && descriptionReady;
return !!title && !!reference && !!offerList;
}
""",
polling=1000,

View File

@ -205,7 +205,6 @@ def fetch_apec(
raise typer.Exit(code=1)
deduplicated_listings = dedupe_apec_listings(normalized_listings)
should_fail_after_write = successful_fetch_count > 0 and not normalized_listings
failed_count = len({error.url for error in listing_errors})
run_meta = ApecRunMeta(
run_id=run_id,
@ -240,9 +239,6 @@ def fetch_apec(
f"deduplicated={len(deduplicated_listings)} failed={failed_count}"
)
if should_fail_after_write:
raise typer.Exit(code=1)
def main() -> None:
app()

View File

@ -324,8 +324,10 @@ def test_fetch_listing_html_waits_for_rendered_offer_content(monkeypatch) -> Non
assert html == "<html>rendered offer</html>"
assert len(page.waited_functions) == 1
assert ".container-details-offer h1" in page.waited_functions[0][0]
assert ".ref-offre" in page.waited_functions[0][0]
assert ".details-offer-list" in page.waited_functions[0][0]
assert "Descriptif du poste" in page.waited_functions[0][0]
assert "Descriptif du poste" not in page.waited_functions[0][0]
assert page.waited_functions[0][1] == 1000
@ -338,10 +340,10 @@ def test_fetch_listing_html_uses_explicit_company_fallback_chain(monkeypatch) ->
)
wait_script = page.waited_functions[0][0]
assert "companySelectors" in wait_script
assert ".card-ents .ents-name" in wait_script
assert ".card-ents-quote" in wait_script
assert ".details-offer-list li:first-of-type" in wait_script
assert "companySelectors" not in wait_script
assert ".container-details-offer h1" in wait_script
assert ".ref-offre" in wait_script
assert ".details-offer-list" in wait_script
def test_fetch_listing_html_rejects_non_apec_hosts() -> None:

View File

@ -1068,7 +1068,7 @@ def test_fetch_apec_preserves_snapshot_and_run_meta_when_normalization_fails(
result = CliRunner().invoke(app, ["fetch-apec", "--data-root", str(data_root)])
assert result.exit_code == 1
assert result.exit_code == 0
assert "fetched=1" in result.stdout
assert "normalized=0" in result.stdout
assert "deduplicated=0" in result.stdout
@ -1150,7 +1150,7 @@ def test_fetch_apec_writes_artifacts_when_every_normalization_attempt_fails(
result = CliRunner().invoke(app, ["fetch-apec", "--data-root", str(data_root)])
assert result.exit_code == 1
assert result.exit_code == 0
assert "fetched=2" in result.stdout
assert "normalized=0" in result.stdout
assert "deduplicated=0" in result.stdout