Skip to content
Closed
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
20 changes: 20 additions & 0 deletions unfold_studio/integration_tests/test_files/base_story_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,23 @@ def _wait_for_input_box_with_placeholder(self, placeholder):
pass
time.sleep(0.5)
raise TimeoutException(f"Input box with placeholder '{placeholder}' not found or not enabled within {timeout} seconds")

def assert_error_message(self, expected_error, timeout=10):
try:
WebDriverWait(self.driver, timeout).until(
lambda d: any(
expected_error == error_element.text.strip()
for error_element in d.find_elements(By.CLASS_NAME, "error")
)
)
print_green(f"✓ Found exact error message: '{expected_error}'")
return True
except TimeoutException:
error_elements = self.driver.find_elements(By.CLASS_NAME, "error")
error_texts = [elem.text.strip() for elem in error_elements]
print(f"✗ Error message not found. Expected: '{expected_error}'")
print(f"Found error elements: {error_texts}")
raise TimeoutException(
f"Timeout waiting for exact error message: '{expected_error}'\n"
f"Found error elements: {error_texts}"
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main():
'test_input_generate.py',
'test_input_generate2.py',
'test_input_generate3.py',
'test_continue.py'
'test_continue.py',
]

success_count = 0
Expand Down
19 changes: 19 additions & 0 deletions unfold_studio/unfold_studio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ def include(base, new):
include(variables, iVars)
include(knots, iKnots)

# Check for undefined input variables
input_vars = self.get_input_variables()
undefined_vars = [var for var in input_vars if var not in variables]
if undefined_vars:
raise Story.PreprocessingError(
StoryError.ErrorTypes.PREPROCESS_ERROR,
message=f"Input variables must be defined before use. Undefined variables: {', '.join(undefined_vars)}"
)

inkText = "\n".join(
self.external_function_declarations() + # call-outs to javascript
[l for i, l in variables.values()] + # lifted variable initializations
Expand Down Expand Up @@ -372,6 +381,16 @@ def get_variable_initializations(self):
variableInits[result.group(2)] = (lineNum+1, line)
return variableInits

def get_input_variables(self):
"Returns a set of variable names used in input calls"
input_vars = set()
input_pattern = r'~\s*input\s*\([^,]+,\s*"([^"]+)"\)'
for line in self.ink.split("\n"):
match = re.search(input_pattern, line)
if match:
input_vars.add(match.group(1))
return input_vars

def get_ink_preamble(self, stripped=True):
"Returns the content before the first knot"
try:
Expand Down
Loading