"""Positive control: plant GSM8K test questions inside real FineWeb documents.
Writes full.parquet (whole question inserted at a random char offset) and half.parquet
(first half of the question's words). Seed 0; documents = first 2,638 rows of
sample/10BT/001_00000.parquet. Usage: python inject.py <gsm8k_test.parquet> <fineweb_shard.parquet> <outdir>"""
import random, sys, pyarrow as pa, pyarrow.parquet as pq
test, shard, out = sys.argv[1:]
random.seed(0)
te = pq.read_table(test).column("question").to_pylist()
docs = next(pq.ParquetFile(shard).iter_batches(batch_size=2638, columns=["text"])).column(0).to_pylist()
full, half = [], []
for i, q in enumerate(te):
    d = docs[i]; p = random.randint(0, len(d)); full.append(d[:p] + "\n" + q + "\n" + d[p:])
    w = q.split(); h = " ".join(w[:len(w) // 2]); d = docs[1319 + i]; p = random.randint(0, len(d))
    half.append(d[:p] + " " + h + " " + d[p:])
pq.write_table(pa.table({"text": full}), f"{out}/full.parquet")
pq.write_table(pa.table({"text": half}), f"{out}/half.parquet")
