harbor run -t openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4137harbor download openthoughts/tasktrove-exp-flat25-pseudocode-v2-5k-pseudocode-4137PSEUDOCODE TASK SPECIFICATION (ONLY)
Goal Implement a self-contained, in-memory “fake browser” API that models a wait.html-like DOM and provides query methods used by a pytest suite.
Data model CLASS Node TAG: STRING ID: STRING VISIBLE: BOOLEAN CHILDREN: LIST OF Node
FUNCTION build_waithtml_dom() -> Node // returns a deterministic in-memory DOM rooted at a body node body = Node(TAG="body", ID=None, VISIBLE=True, CHILDREN=[ // 3 visible divs (in document order) Node(TAG="div", ID="foo", VISIBLE=True, CHILDREN=[]), Node(TAG="div", ID="buttons", VISIBLE=True, CHILDREN=[]), Node(TAG="div", ID="baz", VISIBLE=True, CHILDREN=[]), // 3 hidden divs (in document order) Node(TAG="div", ID="bar", VISIBLE=False, CHILDREN=[]), Node(TAG="div", ID="also_hidden", VISIBLE=False, CHILDREN=[]), Node(TAG="div", ID="hidden3", VISIBLE=False, CHILDREN=[]) ]) RETURN body
API surface CLASS Browser FIELD: root_body: Node // result of build_waithtml_dom()
CONSTRUCTOR:
root_body <- build_waithtml_dom()
METHOD body() -> Wrapper
// Return a scope wrapper representing the page body
RETURN Wrapper(scope_root=root_body)
METHOD div(visible: BOOL, index: INTEGER=None, id: STRING|REGEX=None, xpath: STRING=None, css: STRING=None) -> Wrapper
// Find a single matching <div> inside the current scope (body by default)
// visible must be strictly boolean; otherwise raise TypeError with exact message
_validate_visible(visible)
matches <- _find_matches(scope=root_body, tag="div", visible=visible, id=id, xpath=xpath, css=css)
IF index IS NOT NULL:
IF index < 0 OR index >= LENGTH(matches): RETURN None
chosen <- matches[index]
ELSE:
chosen <- FIRST_ELEMENT(matches)
IF chosen IS NULL: RETURN None
RETURN Wrapper(scope_root=chosen)
METHOD divs(visible: BOOL) -> LIST OF Wrapper
_validate_visible(visible)
matches <- _find_matches(scope=root_body, tag="div", visible=visible, id=NULL, xpath=None, css=None)
RETURN [Wrapper(scope_root=n) FOR n IN matches]
METHOD element(visible: BOOL, xpath: STRING=None, css: STRING=None, id: STRING|REGEX=None) -> Wrapper
_validate_visible(visible)
matches <- _find_matches(scope=root_body, tag=None, visible=visible, id=id, xpath=xpath, css=css)
chosen <- FIRST_ELEMENT(matches)
RETURN Wrapper(scope_root=chosen) IF chosen IS NOT NULL ELSE NULL
CLASS Wrapper FIELD: scope_root: Node // the underlying node this wrapper represents
PROPERTY id -> scope_root.ID
// Allow chaining back to queries within this scope
METHOD element(...same_signature_as Browser.element) -> Wrapper
METHOD div(...same_signature_as Browser.div) -> Wrapper
METHOD divs(...same_signature_as Browser.divs) -> LIST OF Wrapper
Internal helpers (PRIVATE to Browser) FUNCTION _validate_visible(v) IF NOT ISINSTANCE(v, BOOL) RAISE TypeError("expected one of {!r}, got 'true':{}".FORMAT([BOOL], STRING(v)))
FUNCTION _find_matches(scope_root: Node, tag: STRING|NONE, visible: BOOL, id: STRING|REGEX|NONE, xpath: STRING|NONE, css: STRING|NONE) -> LIST OF Node // If xpath present: delegate to _evaluate_xpath(scope_root, visible, xpath) // If css present: delegate to _evaluate_css(scope_root, visible, css) // Else: perform DFS from scope_root matching: // - tag if tag is provided (e.g., "div") // - node.visible == visible // - id matches: if id is STRING -> exact match; if REGEX -> regex.search(node.id) is not None // Return in document order (DFS order)
FUNCTION _evaluate_xpath(root: Node, visible: BOOL, xpath: STRING) -> Node // Minimal support for patterns like ".//div[@id="foo"]" // Extract target_id within @id="..." // If pattern matches: Find first descendant div with id == target_id and node.visible == visible // Return that Node or NULL
FUNCTION _evaluate_css(root: Node, visible: BOOL, css: STRING) -> Node // Minimal support for patterns like "div#foo" // If pattern matches: Find first descendant node with tag == "div" AND id == target_id AND node.visible == visible // Return that Node or NULL
FUNCTION _dfs(scope: Node) -> GENERATOR OF Node YIELD scope FOR child IN scope.CHILDREN: YIELD FROM _dfs(child)
Data initialization details
Usage patterns (examples)
Constraints
Deliverables
Acceptance criteria (implicit)