Read Gem boards through the job board's GraphQL API
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76187d5862
commit
1fc9668110
5 files changed
+335
No files matched your search
@@ -0,0 +1,152 @@
|
||||
"""Gem: `gem:<board>` for jobs.gem.com/<board>, one GraphQL POST for the
|
||||
whole board and one more for a role's text and date. The board is the path
|
||||
after `jobs.gem.com/`, and it is case-sensitive (`Productboard` is an empty
|
||||
board where `productboard` is not).
|
||||
|
||||
The two queries below were read out of Gem's page scripts
|
||||
(`static.gem.com/scripts/jobBoards.*.js` and `ExternalJobBoardList.*.js`) on
|
||||
2026-09-29 and run against Productboard's and sennder's boards; the schema is
|
||||
Gem's own and not documented, so a new bundle can rename a field. Each query is
|
||||
one constant, and an answer that lacks the shape read here fails with an error
|
||||
that says which part is missing rather than reading as an empty board. The
|
||||
endpoint answered with no Origin and no Referer header, so none is sent. An
|
||||
unknown board answers 200 with an empty list, like a board with no role open.
|
||||
|
||||
The listing has no description and no date; both are on the role's page.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from desk.sources import strip_html
|
||||
|
||||
from ._shared import Get, Page, Row, only, parse_dt
|
||||
|
||||
NAME = "gem"
|
||||
LABEL = "Gem"
|
||||
KEEP_CASE = True
|
||||
PATTERNS = (r"jobs\.gem\.com/([A-Za-z0-9_-]+)",)
|
||||
|
||||
_HOST = "jobs.gem.com"
|
||||
_API = f"https://{_HOST}/api/public/graphql"
|
||||
|
||||
#: A board is one path segment of letters, digits, `-` and `_`. It travels as a
|
||||
#: GraphQL variable and never into a host name, so the host stays Gem's.
|
||||
_BOARD = re.compile(r"[A-Za-z0-9_-]+")
|
||||
|
||||
#: Every role of a board in one answer, with no paging and no total.
|
||||
LIST_QUERY = (
|
||||
"query JobBoardList($boardId: String!) { oatsExternalJobPostings(boardId: $boardId) "
|
||||
"{ jobPostings { id extId title locations { id name city isoCountry isRemote extId } "
|
||||
"job { id department { id name extId } locationType employmentType } } } }")
|
||||
|
||||
#: One role's description and the date it was first published.
|
||||
DETAIL_QUERY = (
|
||||
"query ExternalJobPosting($boardId: String!, $extId: String!) "
|
||||
"{ oatsExternalJobPosting(boardId: $boardId, extId: $extId) "
|
||||
"{ id title descriptionHtml extId firstPublishedTsSec "
|
||||
"locations { id extId name city isoCountry isRemote } "
|
||||
"job { id locationType employmentType requisitionId teamDisplayName "
|
||||
"department { id extId name } } compensationHtml } }")
|
||||
|
||||
#: `job.locationType` -> `store._remote`'s words.
|
||||
_REMOTE = {"IN_OFFICE": "onsite", "HYBRID": "hybrid", "REMOTE": "remote"}
|
||||
|
||||
|
||||
def slug_ok(slug: str) -> bool:
|
||||
return bool(_BOARD.fullmatch(slug))
|
||||
|
||||
|
||||
def allowed(slug: str) -> Callable[[str], bool]:
|
||||
return only(_HOST)
|
||||
|
||||
|
||||
def careers_url(slug: str) -> str:
|
||||
return f"https://{_HOST}/{slug}"
|
||||
|
||||
|
||||
def robots_page(slug: str) -> str:
|
||||
return careers_url(slug)
|
||||
|
||||
|
||||
def _ask(get: Get, operation: str, query: str, variables: dict[str, str],
|
||||
path: str) -> Any:
|
||||
"""One GraphQL call, and the part of its answer at `data.<path>`. An
|
||||
`errors` list or a `data` without the key is Gem's schema having moved (or
|
||||
a refused query), and is raised as such; a `null` at the key is returned."""
|
||||
answer = json.loads(get(_API, method="POST", payload={
|
||||
"operationName": operation, "variables": variables, "query": query}))
|
||||
if not isinstance(answer, dict):
|
||||
raise ValueError(f"not a Gem answer: {type(answer).__name__}")
|
||||
if answer.get("errors"):
|
||||
first = answer["errors"][0]
|
||||
message = first.get("message") if isinstance(first, dict) else first
|
||||
raise ValueError(f"Gem's {operation} query was refused: {message}")
|
||||
data = answer.get("data")
|
||||
if not isinstance(data, dict) or path not in data:
|
||||
raise ValueError(f"Gem's {operation} answer has no {path}; the query may be out of date")
|
||||
return data[path]
|
||||
|
||||
|
||||
def page(get: Get, slug: str, cursor: Any) -> Page:
|
||||
"""The one page there is: `data.oatsExternalJobPostings.jobPostings`."""
|
||||
board = _ask(get, "JobBoardList", LIST_QUERY, {"boardId": slug}, "oatsExternalJobPostings")
|
||||
postings = board.get("jobPostings") if isinstance(board, dict) else None
|
||||
if not isinstance(postings, list):
|
||||
raise ValueError("Gem's JobBoardList answer has no jobPostings list; "
|
||||
"the query may be out of date")
|
||||
return postings, [{"id": p.get("extId") or p.get("id") or ""} for p in postings], None, None
|
||||
|
||||
|
||||
def rows(postings: list[dict[str, Any]], slug: str) -> list[Row]:
|
||||
"""A role has `extId` (a number from a synced Greenhouse, else an opaque
|
||||
string; the role's page is `jobs.gem.com/<board>/<extId>`), `title`,
|
||||
`locations` (`name`, `city`, `isoCountry` as ISO alpha-3, `isRemote`) and
|
||||
`job` (`department`, `locationType`, `employmentType`). No pay is stated
|
||||
in the list."""
|
||||
out = []
|
||||
for p in postings:
|
||||
title = (p.get("title") or "").strip()
|
||||
ext_id = str(p.get("extId") or "")
|
||||
if not title or not ext_id:
|
||||
continue
|
||||
locations = p.get("locations") or []
|
||||
places: list[str] = []
|
||||
for loc in locations:
|
||||
place = str(loc.get("city") or loc.get("name") or "").strip()
|
||||
if place and place not in places:
|
||||
places.append(place)
|
||||
job = p.get("job") or {}
|
||||
remote = _REMOTE.get(str(job.get("locationType") or "").upper())
|
||||
if remote is None and locations and all(loc.get("isRemote") for loc in locations):
|
||||
remote = "remote"
|
||||
out.append({
|
||||
"source_id": ext_id,
|
||||
"title": title,
|
||||
"location": "; ".join(places),
|
||||
"url": f"{careers_url(slug)}/{ext_id}",
|
||||
"posted": None, # only the role's own query has a date
|
||||
"department": str((job.get("department") or {}).get("name") or "").strip(),
|
||||
"description": "",
|
||||
"remote": remote,
|
||||
"salary_text": "",
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
def detail(get: Get, slug: str, row: Row) -> dict[str, Any]:
|
||||
"""`oatsExternalJobPosting` of the role: `descriptionHtml` and
|
||||
`firstPublishedTsSec` (epoch seconds). `compensationHtml` was null on the
|
||||
roles read and is left alone."""
|
||||
role = _ask(get, "ExternalJobPosting", DETAIL_QUERY,
|
||||
{"boardId": slug, "extId": row["source_id"]}, "oatsExternalJobPosting")
|
||||
if not isinstance(role, dict):
|
||||
raise ValueError(f"Gem has no role {row['source_id']} on {slug}")
|
||||
text = html.unescape(strip_html(role.get("descriptionHtml") or ""))
|
||||
return {"description": " ".join(text.split()),
|
||||
"posted": parse_dt(role.get("firstPublishedTsSec"))}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"data":{"oatsExternalJobPosting":{"id":"T2F0c0pvYlBvc3Q6MTA0NDAzNA==","title":"Staff AI Product Engineer (Prague/Brno/Remote EU)","descriptionHtml":"<div><strong>Only the best engineers are being built here.</strong></div><div>At Productboard, we are defining AI-first Product Engineering. Not as a one-time achievement, but as a baseline we raise every time we reach it. We remove every bottleneck as it surfaces and rebuild how product teams work from first principles, not just adding AI to existing workflows.</div><div>AI tools are everywhere now. Agents can write code. That\u2019s today\u2019s baseline.What we're building is the environment where the baseline makes you better: focused on outcomes, writing specs that agents build from, leveling up with every feature you ship.</div><div>We are defining what AI-native product development becomes. We're all in.</div><h3><strong>What you will build</strong></h3><div>You'd lead the architectural work that makes our codebase AI-native. Specifically:</div><ul><li class=\"\"><strong>Agent-native architecture standards.</strong> Clear API contracts, semantic naming, well-defined module boundaries. The patterns that keep AI effective as our systems grow.</li><li class=\"\"><strong>A context infrastructure layer.</strong> Repo-versioned guidance that AI tools load automatically \u2014 improving the output of Cursor, Claude Code, and Codex simultaneously.</li><li class=\"\"><strong>Self-healing workflows for incidents.</strong> Agents that triage alerts, pull logs, surface relevant history, suggest remediation. Humans intervene where judgment matters.</li><li class=\"\"><strong>Agent workflows that go beyond chat.</strong> Multi-step reasoning, tool use, autonomous task execution with human-gated checkpoints \u2014 for product features, not internal demos.</li><li class=\"\"><strong>Systematic optimization of AI code review.</strong> Earlier detection of correctness, security, and maintainability issues, with the noise filtered out before it reaches a human reviewer.</li></ul><h3>The opportunity</h3><div>The first shift in our teams has already happened: agents write code. That\u2019s the baseline everywhere. Now we\u2019re building an AI-first Product Engineering organization where learning matters as much as shipping.</div><div>Only a few companies build a product that makes them better. What we\u2019re building next is a single place where work lives. Specs, plans, and full product context live in Productboard. There\u2019s a seamless loop between <a href=\"https://www.productboard.com/product/spark/\" rel=\"noopener noreferrer\" target=\"_blank\">Spark</a>, our AI agent, and the coding agents. Engineers can steer from anywhere and focus on directing the work instead of typing it all out.</div><div>Our own teams run on Productboard and Spark, so the feedback loop isn't a survey next quarter. It's the next conversation you overhear.</div><div>Imagine you ship a feature before lunch and by the afternoon, half the floor is working with it. Not in a demo, not on a roadmap slide: in our real work, minutes after you merged.</div><div>We feel the gaps our customers feel, and we close them first. Every feature goes straight to real product teams solving real problems, starting with ours.</div><div>We are looking for a Staff AI Engineer who wants to build this from the inside.</div><h3>Why this matters for your career</h3><div><strong>Engineers own more.</strong> Not just the code: the outcome it drives.</div><div>You won't just use AI tools. You will shape the architecture that makes agents effective, define the workflows that make them reliable, and build the evaluation systems that make them trustworthy.</div><div>This is where you become a pure product engineer. Someone who owns the problem, the trade-offs, and the result, not just the implementation. Every maker has an orchestra. The craft is knowing what it should play. And we never outsource our thinking.</div><div>The skills you build here (designing codebases agents can work in confidently, writing specs that carry your judgment into every build, building evaluations that catch what AI misses) will define senior engineering for the next decade. What you learn here doesn't just make you faster today. It makes you more valuable for years to come.</div><h3><strong>What you will do</strong></h3><div>We're hiring a Staff AI Engineer to own the architectural layer that makes this real, working alongside our engineers, PMs, and designers shipping AI-first product features end-to-end. You'd ship code, set technical direction, and shape decisions about what's worth building. Your north star here will be: get from idea to validated learning twice as fast.</div><h3><strong>How we work</strong></h3><div>We've moved away from process and toward judgment. The shift looks like this:</div><ul><li class=\"\"><strong>One named driver per initiative.</strong> End-to-end ownership of the outcome, the path, the decisions, and the learnLine truncated
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"data":{"oatsExternalJobPosting":{"id":"T2F0c0pvYlBvc3Q6NzU5NjA4Mg==","title":"Staff Fullstack DevX Engineer (Prague/Brno/Remote EU)","descriptionHtml":"<div><strong style=\"color: rgb(0, 0, 0); background-color: transparent;\">Only the best engineers are being built here.</strong></div><div>At Productboard, we are defining AI-first Product Engineering. Not as a one-time achievement, but as a baseline we raise every time we reach it. We remove every bottleneck as it surfaces and rebuild how product teams work from first principles, not just adding AI to existing workflows.</div><div>AI tools are everywhere now. Agents can write code. That\u2019s today\u2019s baseline.What we're building is the environment where the baseline makes you better: focused on outcomes, writing specs that agents build from, leveling up with every feature you ship.</div><div>We are defining what AI-native product development becomes. We're all in.</div><h3><strong style=\"color: rgb(0, 0, 0); background-color: transparent;\">What you will build</strong></h3><div><span style=\"color: rgb(0, 0, 0); background-color: transparent;\">You'd lead the architectural work that makes our codebase AI-native. Specifically:</span></div><ul><li class=\"\"><strong style=\"background-color: transparent;\">Agent-native architecture standards.</strong><span style=\"background-color: transparent;\"> Clear API contracts, semantic naming, well-defined module boundaries. The patterns that keep AI effective as our systems grow.</span></li><li class=\"\"><strong style=\"background-color: transparent;\">A context infrastructure layer.</strong><span style=\"background-color: transparent;\"> Repo-versioned guidance that AI tools load automatically \u2014 improving the output of Cursor, Claude Code, and Codex simultaneously.</span></li><li class=\"\"><strong style=\"background-color: transparent;\">Self-healing workflows for incidents.</strong><span style=\"background-color: transparent;\"> Agents that triage alerts, pull logs, surface relevant history, suggest remediation. Humans intervene where judgment matters.</span></li><li class=\"\"><strong style=\"background-color: transparent;\">Agent workflows that go beyond chat.</strong><span style=\"background-color: transparent;\"> Multi-step reasoning, tool use, autonomous task execution with human-gated checkpoints \u2014 for product features, not internal demos.</span></li><li class=\"\"><strong style=\"background-color: transparent;\">Systematic optimization of AI code review.</strong><span style=\"background-color: transparent;\"> Earlier detection of correctness, security, and maintainability issues, with the noise filtered out before it reaches a human reviewer.</span></li></ul><h3><strong style=\"color: rgb(0, 0, 0); background-color: transparent;\">The opportunity</strong></h3><div>The first shift in our teams has already happened: agents write code. That\u2019s the baseline everywhere. Now we\u2019re building an AI-first Product Engineering organization where learning matters as much as shipping.</div><div>Only a few companies build a product that makes them better. What we\u2019re building next is a single place where work lives. Specs, plans, and full product context live in Productboard. There\u2019s a seamless loop between <a href=\"https://www.productboard.com/product/spark/\" rel=\"noopener noreferrer\" target=\"_blank\">Spark</a>, our AI agent, and the coding agents. Engineers can steer from anywhere and focus on directing the work instead of typing it all out.</div><div>Our own teams run on Productboard and Spark, so the feedback loop isn't a survey next quarter. It's the next conversation you overhear.</div><div>Imagine you ship a feature before lunch and by the afternoon, half the floor is working with it. Not in a demo, not on a roadmap slide: in our real work, minutes after you merged.</div><div>We feel the gaps our customers feel, and we close them first. Every feature goes straight to real product teams solving real problems, starting with ours.</div><div>We are looking for a Staff Full-stack DevX Engineer who wants to build this from the inside.</div><h3><strong style=\"color: rgb(0, 0, 0); background-color: transparent;\">Why this matters for your career</strong></h3><div><strong>Engineers own more.</strong> Not just the code: the outcome it drives.</div><div>You won't just use AI tools. You will shape the architecture that makes agents effective, define the workflows that make them reliable, and build the evaluation systems that make them trustworthy.</div><div>This is where you become a pure product engineer. Someone who owns the problem, the trade-offs, and the result, not just the implementation. Every maker has an orchestra. The craft is knowing what it should play. And we never outsource our thinking.</div><div>The skills you build here (designing codebases agents can work in confidently, writing specs that carry your judgment into every build, building evaluations that catch whatLine truncated
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"data":{"oatsExternalJobPostings":{"jobPostings":[{"id":"T2F0c0pvYlBvc3Q6MTA0NDAzNA==","extId":"8080046002","title":"Staff AI Product Engineer (Prague/Brno/Remote EU)","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"}],"job":{"id":"T2F0c0pvYjo2MDYxMDY=","department":{"id":"37338","name":"Product Engineering","extId":"4065161002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NTY0ODcxMw==","extId":"am9icG9zdDpS7XehojHQK_NnncgSKWoQ","title":"Staff Full-stack Product Engineer (Prague/Brno/Remote EU)","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"}],"job":{"id":"T2F0c0pvYjo2NjEyMTk=","department":{"id":"37338","name":"Product Engineering","extId":"4065161002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NTY0ODcxNg==","extId":"am9icG9zdDqWC1V_RM7U6ORvTd1Iu64r","title":"Staff Backend Product Engineer (Prague/Brno/Remote EU)","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"},{"id":"38772","name":"Remote Europe","city":"Remote Europe","isoCountry":"CZE","isRemote":true,"extId":"4030754002"},{"id":"38781","name":"Brno (Hybrid)","city":"Brno","isoCountry":"CZE","isRemote":false,"extId":"4051723002"}],"job":{"id":"T2F0c0pvYjoyMDg5NTcx","department":{"id":"37338","name":"Product Engineering","extId":"4065161002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NzU2OTA5MQ==","extId":"am9icG9zdDpfq1dHcevndHGSzK_aYE1g","title":"Marketing Systems Operations Lead","locations":[{"id":"38780","name":"San Francisco","city":"San Francisco","isoCountry":"USA","isRemote":false,"extId":"4030598002"}],"job":{"id":"T2F0c0pvYjo2NTkyMzYy","department":{"id":"37379","name":"GTM Ops","extId":"4068217002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NzU5NjA4Mg==","extId":"am9icG9zdDq5-IOakBvxHzWhMPnTzoPp","title":"Staff Fullstack DevX Engineer (Prague/Brno/Remote EU)","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"},{"id":"38772","name":"Remote Europe","city":"Remote Europe","isoCountry":"CZE","isRemote":true,"extId":"4030754002"},{"id":"38781","name":"Brno (Hybrid)","city":"Brno","isoCountry":"CZE","isRemote":false,"extId":"4051723002"}],"job":{"id":"T2F0c0pvYjo2NjA4ODU3","department":{"id":"37338","name":"Product Engineering","extId":"4065161002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NzYwMjE1NA==","extId":"am9icG9zdDoaMPkCxlUbsYDApcWCdyCP","title":"Staff Frontend Product Engineer (Prague/Brno/Remote EU)","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"}],"job":{"id":"T2F0c0pvYjo2NjA4ODU4","department":{"id":"37338","name":"Product Engineering","extId":"4065161002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NzYwMzc4Mg==","extId":"am9icG9zdDpGGIKW-IlxhJ2EnwVAtLRB","title":"Staff Full-stack Product Engineer, Growth (Prague/Brno/Remote EU) ","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"}],"job":{"id":"T2F0c0pvYjo2NjEyMTk=","department":{"id":"37338","name":"Product Engineering","extId":"4065161002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6NzcyNzc0Ng==","extId":"am9icG9zdDq9ZHg3x3sdBTy6feA4MZ9f","title":"Digital Marketing Manager","locations":[{"id":"38780","name":"San Francisco","city":"San Francisco","isoCountry":"USA","isRemote":false,"extId":"4030598002"}],"job":{"id":"T2F0c0pvYjo2NjkyOTAw","department":{"id":"37358","name":"Digital Marketing","extId":"4076635002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6Nzk0NDYyMA==","extId":"am9icG9zdDp906RvIzQmjA9funJO3zB1","title":"AI Data Engineer","locations":[{"id":"38771","name":"Prague (Hybrid)","city":"Prague","isoCountry":"CZE","isRemote":false,"extId":"4029634002"},{"id":"38781","name":"Brno (Hybrid)","city":"Brno","isoCountry":"CZE","isRemote":false,"extId":"4051723002"}],"job":{"id":"T2F0c0pvYjo2ODE0MzAz","department":{"id":"37352","name":"Data","extId":"4076631002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6ODAzMTI0MQ==","extId":"am9icG9zdDqzuJaiLLHinwNQLMZuqlux","title":"Digital Marketing Specialist ","locations":[{"id":"38780","name":"San Francisco","city":"San Francisco","isoCountry":"USA","isRemote":false,"extId":"4030598002"}],"job":{"id":"T2F0c0pvYjo2NjkyOTAw","department":{"id":"37358","name":"Digital Marketing","extId":"4076635002"},"locationType":"HYBRID","employmentType":"FULL_TIME"}},{"id":"T2F0c0pvYlBvc3Q6ODA1NTY3NQ==","extId":"am9icG9zdDrYRR2Ri8264a07xF_f9eI3","title":"AI Customer Success Engineer ","locatioLine truncated
|
||||
@@ -0,0 +1,180 @@
|
||||
"""The Gem host module against Productboard's saved listing and two saved role
|
||||
answers. No network."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from app.jobs import discover # noqa: E402
|
||||
from plugins import ats, atshosts # noqa: E402
|
||||
from plugins.atshosts import gem # noqa: E402
|
||||
|
||||
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
|
||||
API = "https://jobs.gem.com/api/public/graphql"
|
||||
|
||||
|
||||
def _read(name: str) -> bytes:
|
||||
return (FIXTURES / name).read_bytes()
|
||||
|
||||
|
||||
def _get_of(answers: dict[str, bytes | Exception], asked: list[dict[str, Any]]) -> Any:
|
||||
"""A `get` that answers a GraphQL call by its operation name."""
|
||||
def get(url: str, *, method: str = "GET", payload: Any = None,
|
||||
headers: dict[str, str] | None = None) -> bytes:
|
||||
assert url == API and method == "POST"
|
||||
asked.append(payload | {"headers": headers})
|
||||
answer = answers[payload["operationName"]]
|
||||
if isinstance(answer, Exception):
|
||||
raise answer
|
||||
return answer
|
||||
return get
|
||||
|
||||
|
||||
def _listing() -> dict[str, bytes | Exception]:
|
||||
return {"JobBoardList": _read("gem.json")}
|
||||
|
||||
|
||||
def test_a_listing_becomes_rows() -> None:
|
||||
asked: list[dict[str, Any]] = []
|
||||
decoded, results, total, cursor = gem.page(_get_of(_listing(), asked), "productboard", None)
|
||||
assert asked == [{"operationName": "JobBoardList", "variables": {"boardId": "productboard"},
|
||||
"query": gem.LIST_QUERY, "headers": None}]
|
||||
assert (total, cursor) == (None, None) and len(results) == 11
|
||||
rows = gem.rows(decoded, "productboard")
|
||||
assert len(rows) == 11
|
||||
first, backend = rows[0], rows[2]
|
||||
assert first["source_id"] == "8080046002" # numeric, from a synced Greenhouse
|
||||
assert first["title"] == "Staff AI Product Engineer (Prague/Brno/Remote EU)"
|
||||
assert first["url"] == "https://jobs.gem.com/productboard/8080046002"
|
||||
assert first["department"] == "Product Engineering" and first["remote"] == "hybrid"
|
||||
assert first["location"] == "Prague"
|
||||
assert (first["posted"], first["description"], first["salary_text"]) == (None, "", "")
|
||||
assert backend["source_id"] == "am9icG9zdDqWC1V_RM7U6ORvTd1Iu64r" # opaque
|
||||
assert backend["location"] == "Prague; Remote Europe; Brno"
|
||||
assert len({r["source_id"] for r in rows}) == 11
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("kind", "flags", "remote"), [
|
||||
("IN_OFFICE", [False], "onsite"), ("HYBRID", [True], "hybrid"), ("REMOTE", [False], "remote"),
|
||||
(None, [True, True], "remote"), (None, [True, False], None), (None, [], None),
|
||||
("SOMETHING_NEW", [False], None)])
|
||||
def test_remote_is_the_location_type_then_the_locations(
|
||||
kind: str | None, flags: list[bool], remote: str | None) -> None:
|
||||
posting = {"extId": "1", "title": "Role", "job": {"locationType": kind},
|
||||
"locations": [{"city": "X", "isRemote": f} for f in flags]}
|
||||
assert gem.rows([posting], "acme")[0]["remote"] == remote
|
||||
|
||||
|
||||
def test_a_posting_without_a_title_or_an_ext_id_is_left_out() -> None:
|
||||
assert gem.rows([{"extId": "1", "title": " "}, {"extId": "", "title": "Role"}], "acme") == []
|
||||
|
||||
|
||||
def test_the_board_is_read_through_the_app_without_origin_or_referer() -> None:
|
||||
seen: list[httpx.Request] = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
seen.append(request)
|
||||
return httpx.Response(200, content=_read("gem.json"))
|
||||
|
||||
with httpx.Client(transport=httpx.MockTransport(handler)) as client:
|
||||
rows, complete = ats._fetch_rows(client, "gem:productboard")
|
||||
assert len(rows) == 11 and complete
|
||||
(request,) = seen
|
||||
assert str(request.url) == API and request.method == "POST"
|
||||
assert json.loads(request.content)["variables"] == {"boardId": "productboard"}
|
||||
assert "origin" not in request.headers and "referer" not in request.headers
|
||||
assert request.headers["content-type"] == "application/json"
|
||||
|
||||
|
||||
def test_an_empty_board_is_complete_at_zero() -> None:
|
||||
body = b'{"data":{"oatsExternalJobPostings":{"jobPostings":[]}}}'
|
||||
with httpx.Client(transport=httpx.MockTransport(
|
||||
lambda request: httpx.Response(200, content=body))) as client:
|
||||
assert ats._fetch_rows(client, "gem:nobody") == ([], True)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("body", "message"), [
|
||||
(b'{"errors":[{"message":"Cannot query field \\"extId\\""}]}', "refused: Cannot query field"),
|
||||
(b'{"data":{"somethingElse":{}}}', "no oatsExternalJobPostings"),
|
||||
(b'{"data":null}', "no oatsExternalJobPostings"),
|
||||
(b'{"data":{"oatsExternalJobPostings":{"postings":[]}}}', "no jobPostings list"),
|
||||
(b'{"data":{"oatsExternalJobPostings":null}}', "no jobPostings list"),
|
||||
(b'[]', "not a Gem answer"),
|
||||
])
|
||||
def test_an_answer_of_another_shape_fails_with_a_clear_error(body: bytes, message: str) -> None:
|
||||
with pytest.raises(ValueError, match=message):
|
||||
gem.page(_get_of({"JobBoardList": body}, []), "productboard", None)
|
||||
|
||||
|
||||
def test_detail_reads_the_text_and_the_date() -> None:
|
||||
row = {"source_id": "am9icG9zdDq5-IOakBvxHzWhMPnTzoPp"}
|
||||
asked: list[dict[str, Any]] = []
|
||||
found = gem.detail(_get_of({"ExternalJobPosting": _read("gem-detail-2.json")}, asked),
|
||||
"productboard", row)
|
||||
assert asked[0]["operationName"] == "ExternalJobPosting"
|
||||
assert asked[0]["variables"] == {"boardId": "productboard", "extId": row["source_id"]}
|
||||
assert asked[0]["query"] == gem.DETAIL_QUERY
|
||||
assert set(found) <= set(ats.DETAIL_FIELDS)
|
||||
assert found["posted"] == datetime.fromtimestamp(1787574069, tz=UTC)
|
||||
assert found["description"].startswith("Only the best engineers are being built here.")
|
||||
assert "<" not in found["description"] and "&" not in found["description"]
|
||||
|
||||
|
||||
def test_detail_of_a_role_that_is_not_there_raises() -> None:
|
||||
body = b'{"data":{"oatsExternalJobPosting":null}}'
|
||||
with pytest.raises(ValueError, match="no role gone on acme"):
|
||||
gem.detail(_get_of({"ExternalJobPosting": body}, []), "acme", {"source_id": "gone"})
|
||||
|
||||
|
||||
def test_detail_reads_the_numeric_role_too() -> None:
|
||||
found = gem.detail(_get_of({"ExternalJobPosting": _read("gem-detail-1.json")}, []),
|
||||
"productboard", {"source_id": "8080046002"})
|
||||
assert found["posted"] == datetime.fromtimestamp(1753349342, tz=UTC)
|
||||
assert found["description"]
|
||||
|
||||
|
||||
def test_the_slug_the_urls_and_the_allow_list() -> None:
|
||||
assert gem.KEEP_CASE
|
||||
for slug in ("productboard", "Productboard", "senndertechnologies-gmbh", "a_b", "1"):
|
||||
assert gem.slug_ok(slug)
|
||||
assert gem.careers_url("Productboard") == "https://jobs.gem.com/Productboard"
|
||||
assert gem.robots_page("productboard") == "https://jobs.gem.com/productboard"
|
||||
allow = gem.allowed("productboard")
|
||||
assert allow("jobs.gem.com") and allow("JOBS.gem.com")
|
||||
assert not allow("gem.com") and not allow("productboard.gem.com")
|
||||
assert not allow("jobs.gem.com.evil.example") and not allow("localhost")
|
||||
assert atshosts.HOSTS["gem"] is gem and ats.HOSTS["gem"] == "Gem"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("slug", [
|
||||
"", "a@b", "a#b", "a?b", "..", ".", "a/b", "a%2fb", "a:443", "a b", " a", "a\n", "a\r\n",
|
||||
"a.b", "127.0.0.1", "[::1]", "localhost.", "a\\b", "a\"b"])
|
||||
def test_a_hostile_slug_is_refused(slug: str) -> None:
|
||||
assert not gem.slug_ok(slug)
|
||||
assert not ats.is_known_target(f"gem:{slug}")
|
||||
|
||||
|
||||
def test_a_local_word_as_a_slug_still_reaches_gems_host_only() -> None:
|
||||
assert ats.is_known_target("gem:localhost")
|
||||
allow = gem.allowed("localhost")
|
||||
assert allow("jobs.gem.com") and not allow("localhost")
|
||||
|
||||
|
||||
def test_discovery_finds_the_board_keeping_its_case() -> None:
|
||||
page = ('<a href="https://jobs.gem.com/Productboard">Jobs</a>'
|
||||
'<a href="https://jobs.gem.com/api/public/graphql">x</a>'
|
||||
'<a href="https://jobs.gem.com/sennder-gmbh/8080046002">y</a>')
|
||||
assert [(h, s) for h, s, _ in discover.boards_in(page)] == [
|
||||
("gem", "Productboard"), ("gem", "sennder-gmbh")]
|
||||
assert "gem" not in {h for h, _ in discover._UNREADABLE if h not in atshosts.HOSTS}
|
||||
Reference in new issue
Block a user