Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test-level context #2142

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tetele
Copy link
Contributor

@tetele tetele commented Apr 18, 2024

It should be fine to have 2 identical test sentences if their context is different (e.g. "turn off the lights" should mean "turn off all lights" without context and "turn off the lights in this area" when the satellite's area is provided as context).

Although technically you could have passed such a set of sentences to HA, it was impossible to add them to the intents repo until now due to tests not passing.

Part of the cause was the double use of intent.context, both as input context to the test and as expected outcome after the recognition. This PR splits the 2 concerns (input context and expected output context) and allows several identical sentences to be tested, as long as their input contexts differ.

Summary by CodeRabbit

  • New Features

    • Added an optional "context" field to the validation functionality, allowing more flexible test configurations.
  • Improvements

    • Standardized the context specification across various test cases, enhancing consistency and readability.
  • Bug Fixes

    • Removed the requires_context field from the binary sensor intent related to vibration detection, simplifying the configuration.
  • Refactor

    • Moved context fields from the intent level to the test level in various test files, improving the structure and clarity of test scenarios.
  • Tests

    • Enhanced duplicate sentence detection by introducing a unique identifier based on the sentence and context.

@tetele tetele changed the title Fix sentence uniqueness test Add test-level context Apr 18, 2024
@tetele
Copy link
Contributor Author

tetele commented Apr 18, 2024

@balloob @synesthesiam i know the tests will fail, I've only fixed the EN ones for now, but before undertaking the massive task of correcting all tests in all languages, I'd like to get your feedback on the approach here.

@tetele tetele force-pushed the fix-test-sentence-uniqueness branch from 8f5f980 to 59190a0 Compare May 30, 2024 14:51
Copy link

coderabbitai bot commented May 30, 2024

Walkthrough

Walkthrough

The changes introduce a new optional "context" field to the validation function and adjust how context is handled in various test files. This includes moving context specifications to higher levels or test-specific contexts and removing some context requirements. These modifications enhance flexibility and organization in specifying test contexts.

Changes

File Path Change Summary
script/intentfest/validate.py Added an optional "context" field with a dictionary constraint to the "tests" section within the validate function.
sentences/en/binary_sensor_HassGetState.yaml Removed the requires_context field for a binary sensor intent related to vibration detection.
tests/en/binary_sensor_HassGetState.yaml Removed the context section for the HassGetState intent.
tests/en/cover_HassTurnOff.yaml, tests/en/cover_HassTurnOn.yaml, tests/en/fan_HassTurnOff.yaml, tests/en/fan_HassTurnOn.yaml, tests/en/light_HassTurnOff.yaml, tests/en/light_HassTurnOn.yaml Moved the context field from the intent level to higher levels or specific test case levels, specifying areas like "Living Room" or "Bedroom".
tests/en/light_HassLightSet.yaml Added a context field with the value area: Bedroom for each test case under the intent section.
tests/test_language_sentences.py Updated intent_context assignment, introduced a unique identifier for sentences, and modified the check for duplicate sentences using this identifier.

Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 01a0ab6 and 59190a0.

Files selected for processing (11)
  • script/intentfest/validate.py (1 hunks)
  • sentences/en/binary_sensor_HassGetState.yaml (1 hunks)
  • tests/en/binary_sensor_HassGetState.yaml (1 hunks)
  • tests/en/cover_HassTurnOff.yaml (1 hunks)
  • tests/en/cover_HassTurnOn.yaml (1 hunks)
  • tests/en/fan_HassTurnOff.yaml (1 hunks)
  • tests/en/fan_HassTurnOn.yaml (1 hunks)
  • tests/en/light_HassLightSet.yaml (3 hunks)
  • tests/en/light_HassTurnOff.yaml (1 hunks)
  • tests/en/light_HassTurnOn.yaml (1 hunks)
  • tests/test_language_sentences.py (2 hunks)
Additional context used
Path-based instructions (1)
tests/test_language_sentences.py (4)

Pattern */**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

Pattern */**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

Pattern */**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"


Pattern */**(html|markdown|md): - Use sentence-style capitalization also in headings.

Additional comments not posted (28)
tests/en/fan_HassTurnOn.yaml (1)

30-31: Contextual adjustment aligns with PR objectives to handle identical sentences with different contexts.

Verification successful

The context pattern context:\n area: Living Room is present in multiple YAML test files, including tests/en/fan_HassTurnOn.yaml. This confirms that the context adjustment has been applied consistently across the test files.

  • tests/en/fan_HassTurnOn.yaml
  • tests/en/light_HassTurnOn.yaml
  • tests/en/fan_HassTurnOff.yaml
  • tests/en/cover_HassTurnOn.yaml
  • tests/en/light_HassTurnOff.yaml
  • tests/en/media_player_HassMediaPause.yaml
  • tests/en/media_player_HassSetVolume.yaml
  • tests/en/media_player_HassMediaUnpause.yaml
  • tests/en/media_player_HassMediaNext.yaml
  • tests/en/homeassistant_HassStartTimer.yaml
  • tests/fr/light_HassTurnOff.yaml
  • tests/fr/light_HassTurnOn.yaml

This indicates that the context adjustment is integrated correctly with the intent handling logic.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the context adjustment integrates correctly with the intent handling logic.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type yaml $'context:\n  area: Living Room'

Length of output: 239



Script:

#!/bin/bash
# Description: Verify that the context adjustment integrates correctly with the intent handling logic.

# Test: Search for the context pattern in YAML files with multiline mode enabled.
rg --multiline --type yaml $'context:\n  area: Living Room'

Length of output: 59



Script:

#!/bin/bash
# Description: Verify that the context adjustment integrates correctly with the intent handling logic.

# Test: Search for variations of the context pattern in YAML files.
rg --multiline --type yaml 'context:\n\s*area:\s*Living Room'

Length of output: 2879

tests/en/fan_HassTurnOff.yaml (1)

40-41: Contextual adjustment aligns with PR objectives to handle identical sentences with different contexts.

tests/en/cover_HassTurnOff.yaml (1)

68-69: Contextual adjustment aligns with PR objectives to handle identical sentences with different contexts.

tests/en/cover_HassTurnOn.yaml (1)

69-70: Contextual adjustment aligns with PR objectives to handle identical sentences with different contexts.

tests/en/light_HassTurnOff.yaml (1)

66-67: Contextual adjustment aligns with PR objectives to handle identical sentences with different contexts.

tests/en/light_HassTurnOn.yaml (1)

68-69: Contextual adjustment aligns with PR objectives to handle identical sentences with different contexts.

Verification successful

The context adjustment for "area: Living Room" is consistently applied across multiple test files, indicating that the change is integrated correctly with the intent handling logic.

  • tests/en/light_HassTurnOn.yaml
  • tests/fr/light_HassTurnOn.yaml
  • tests/fr/light_HassTurnOff.yaml
  • tests/en/media_player_HassSetVolume.yaml
  • tests/en/fan_HassTurnOn.yaml
  • tests/en/light_HassTurnOff.yaml
  • tests/en/cover_HassTurnOn.yaml
  • tests/en/cover_HassTurnOff.yaml
  • tests/en/fan_HassTurnOff.yaml
  • tests/en/media_player_HassMediaUnpause.yaml
  • tests/en/media_player_HassMediaPause.yaml
  • tests/en/media_player_HassMediaNext.yaml
  • tests/en/homeassistant_HassStartTimer.yaml
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the context adjustment integrates correctly with the intent handling logic.

# Test: Search for the function usage. Expect: Only occurances of the new signature.
rg --type yaml $'context:\n  area: Living Room'

Length of output: 239



Script:

#!/bin/bash
# Description: Verify that the context adjustment integrates correctly with the intent handling logic.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type yaml --multiline $'context:\n  area: Living Room'

Length of output: 59



Script:

#!/bin/bash
# Description: Verify that the context adjustment integrates correctly with the intent handling logic.

# Test: Search for variations of the context pattern in YAML files.
rg --type yaml --multiline 'context:\n\s*area:\s*Living Room'

# Test: Search for related context patterns in other files.
rg --multiline 'context:\n\s*area:\s*Living Room'

Length of output: 5747

tests/en/light_HassLightSet.yaml (3)

43-44: Context specification moved to a higher level in the test structure.

This change aligns with the PR's goal to handle identical test sentences with different contexts more effectively.


108-109: Context specification moved to a higher level in the test structure.

This change aligns with the PR's goal to handle identical test sentences with different contexts more effectively.


151-152: Context specification moved to a higher level in the test structure.

This change aligns with the PR's goal to handle identical test sentences with different contexts more effectively.

tests/test_language_sentences.py (1)

99-99: Updated context handling and unique sentence ID generation.

These changes ensure that sentences with different contexts are treated as unique, preventing duplicate sentence errors and aligning with the PR's objectives.

Also applies to: 110-110, 113-113, 115-115

script/intentfest/validate.py (1)

218-220: Added validation for the "context" field to ensure it does not contain dictionaries.

This change ensures that context specifications are simple and aligns with the PR's objectives to handle context more effectively.

tests/en/binary_sensor_HassGetState.yaml (1)

Line range hint 1-1000: Context fields related to binary sensor vibration detection have been removed as intended.

This change aligns with the PR's objectives to simplify and clarify context handling in test cases.

sentences/en/binary_sensor_HassGetState.yaml (16)

Line range hint 14-14: Removal of requires_context for battery sensors.

This change aligns with the PR's goal to handle context more flexibly. Ensure that the backend logic correctly interprets the absence of this field.


Line range hint 26-26: Removal of requires_context for battery charging sensors.

Similar to the previous comment, this adjustment should be supported by corresponding backend changes to handle context appropriately.


Line range hint 38-38: Removal of requires_context for carbon monoxide sensors.

Ensure that the system's response to carbon monoxide sensor queries remains accurate and context-aware, even without explicit requires_context.


Line range hint 50-50: Removal of requires_context for cold sensors.

Confirm that the removal of this context does not impact the functionality of cold sensor queries within the system.


Line range hint 62-62: Removal of requires_context for connectivity sensors.

As connectivity might often be area-specific, verify that the system can still handle area-based queries effectively without this context.


Line range hint 74-74: Removal of requires_context for door sensors.

This change should simplify the handling of door sensor states. Ensure that the intent processing logic is updated to reflect this change.


Line range hint 86-86: Removal of requires_context for garage door sensors.

Check that the system can still accurately determine the state of garage doors in different areas without the requires_context.


Line range hint 98-98: Removal of requires_context for gas sensors.

This is a critical safety feature. Ensure that the removal of context does not compromise the accuracy and responsiveness of gas detection.


Line range hint 110-110: Removal of requires_context for heat sensors.

Heat sensors often require precise location data. Confirm that the system maintains its accuracy in detecting heat conditions across different areas.


Line range hint 122-122: Removal of requires_context for light sensors.

Lighting conditions can vary significantly by area. Ensure that the system can handle these variations effectively without explicit context.


Line range hint 134-134: Removal of requires_context for lock sensors.

Lock status might be critical for security purposes. Verify that the system still performs reliably in determining lock status across different areas.


Line range hint 146-146: Removal of requires_context for moisture sensors.

Given the importance of moisture detection in preventing damage, ensure that the system's functionality is not impaired by this change.


Line range hint 158-158: Removal of requires_context for motion sensors.

Motion detection often requires specific area context. Confirm that the system can still accurately detect motion without this field.


Line range hint 170-170: Removal of requires_context for occupancy sensors.

Occupancy detection is crucial for automation and security. Ensure that the system handles this effectively without the requires_context.


Line range hint 182-182: Removal of requires_context for opening sensors.

Verify that the system can still accurately report the state of openings, such as windows and doors, without this context.


Line range hint 194-194: Removal of requires_context for plug sensors.

Plugs being a common device in smart homes, ensure that the system can handle queries about their state effectively without needing explicit context.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant