diff --git a/.gitignore b/.gitignore index 198eb62..d8d2261 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,11 @@ __pycache__/ *.py[cod] *$py.class - +# test_usecases.py ubicado en tests/services +import pytest +from unittest.mock import Mock, patch +from app.services.usecases import ChatService +from app.domain import models # C extensions *.so diff --git a/app/domain/ports.py b/app/domain/ports.py index 23ac81e..cbd7d78 100644 --- a/app/domain/ports.py +++ b/app/domain/ports.py @@ -16,7 +16,6 @@ def save_chat(self, chat: models.Chat) -> None: def get_chat(self, chat_id: str) -> models.Chat | None: pass - class AgentPort(abc.ABC): @abc.abstractmethod def __call__(self, query: str) -> dict[str, Any]: @@ -34,7 +33,6 @@ def set_memory_variables(self, history: list[ai.BaseMessage]) -> None: def get_last_response(self) -> str: ... - class TranscriptionPort(ABC): @abstractmethod def transcribe_audio(self, audio_file: bytes) -> str: diff --git a/app/services/usecases.py b/app/services/usecases.py index fbf613f..c1b1425 100644 --- a/app/services/usecases.py +++ b/app/services/usecases.py @@ -50,6 +50,5 @@ def _update_chat(self, chat: models.Chat) -> None: class NoChatFound(Exception): pass - class InputNotProvided(Exception): pass diff --git a/htmlcov/.gitignore b/htmlcov/.gitignore new file mode 100644 index 0000000..ccccf14 --- /dev/null +++ b/htmlcov/.gitignore @@ -0,0 +1,2 @@ +# Created by coverage.py +* diff --git a/htmlcov/class_index.html b/htmlcov/class_index.html new file mode 100644 index 0000000..8b33ea4 --- /dev/null +++ b/htmlcov/class_index.html @@ -0,0 +1,243 @@ + + + + + Coverage report + + + + + +
+
+

Coverage report: + 96% +

+ +
+ +
+ + +
+
+

+ Files + Functions + Classes +

+

+ coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Fileclassstatementsmissingexcludedcoverage
app\__init__.py(no class)000100%
app\domain\__init__.py(no class)000100%
app\domain\models.pyConversation000100%
app\domain\models.pyChat200100%
app\domain\models.py(no class)1300100%
app\domain\ports.pyChatRepository2200%
app\domain\ports.pyAgentPort4400%
app\domain\ports.pyTranscriptionPort1100%
app\domain\ports.py(no class)2200100%
app\logs.py(no class)1400100%
app\services\__init__.py(no class)000100%
app\services\usecases.pyChatService2300100%
app\services\usecases.pyNoChatFound000100%
app\services\usecases.pyInputNotProvided000100%
app\services\usecases.py(no class)1100100%
test\__init__.py(no class)000100%
test\test2.py(no class)8400100%
Total 1767096%
+

+ No items found using the specified filter. +

+
+ + + diff --git a/htmlcov/coverage_html_cb_497bf287.js b/htmlcov/coverage_html_cb_497bf287.js new file mode 100644 index 0000000..1face13 --- /dev/null +++ b/htmlcov/coverage_html_cb_497bf287.js @@ -0,0 +1,733 @@ +// Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +// For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt + +// Coverage.py HTML report browser code. +/*jslint browser: true, sloppy: true, vars: true, plusplus: true, maxerr: 50, indent: 4 */ +/*global coverage: true, document, window, $ */ + +coverage = {}; + +// General helpers +function debounce(callback, wait) { + let timeoutId = null; + return function(...args) { + clearTimeout(timeoutId); + timeoutId = setTimeout(() => { + callback.apply(this, args); + }, wait); + }; +}; + +function checkVisible(element) { + const rect = element.getBoundingClientRect(); + const viewBottom = Math.max(document.documentElement.clientHeight, window.innerHeight); + const viewTop = 30; + return !(rect.bottom < viewTop || rect.top >= viewBottom); +} + +function on_click(sel, fn) { + const elt = document.querySelector(sel); + if (elt) { + elt.addEventListener("click", fn); + } +} + +// Helpers for table sorting +function getCellValue(row, column = 0) { + const cell = row.cells[column] // nosemgrep: eslint.detect-object-injection + if (cell.childElementCount == 1) { + var child = cell.firstElementChild; + if (child.tagName === "A") { + child = child.firstElementChild; + } + if (child instanceof HTMLDataElement && child.value) { + return child.value; + } + } + return cell.innerText || cell.textContent; +} + +function rowComparator(rowA, rowB, column = 0) { + let valueA = getCellValue(rowA, column); + let valueB = getCellValue(rowB, column); + if (!isNaN(valueA) && !isNaN(valueB)) { + return valueA - valueB; + } + return valueA.localeCompare(valueB, undefined, {numeric: true}); +} + +function sortColumn(th) { + // Get the current sorting direction of the selected header, + // clear state on other headers and then set the new sorting direction. + const currentSortOrder = th.getAttribute("aria-sort"); + [...th.parentElement.cells].forEach(header => header.setAttribute("aria-sort", "none")); + var direction; + if (currentSortOrder === "none") { + direction = th.dataset.defaultSortOrder || "ascending"; + } + else if (currentSortOrder === "ascending") { + direction = "descending"; + } + else { + direction = "ascending"; + } + th.setAttribute("aria-sort", direction); + + const column = [...th.parentElement.cells].indexOf(th) + + // Sort all rows and afterwards append them in order to move them in the DOM. + Array.from(th.closest("table").querySelectorAll("tbody tr")) + .sort((rowA, rowB) => rowComparator(rowA, rowB, column) * (direction === "ascending" ? 1 : -1)) + .forEach(tr => tr.parentElement.appendChild(tr)); + + // Save the sort order for next time. + if (th.id !== "region") { + let th_id = "file"; // Sort by file if we don't have a column id + let current_direction = direction; + const stored_list = localStorage.getItem(coverage.INDEX_SORT_STORAGE); + if (stored_list) { + ({th_id, direction} = JSON.parse(stored_list)) + } + localStorage.setItem(coverage.INDEX_SORT_STORAGE, JSON.stringify({ + "th_id": th.id, + "direction": current_direction + })); + if (th.id !== th_id || document.getElementById("region")) { + // Sort column has changed, unset sorting by function or class. + localStorage.setItem(coverage.SORTED_BY_REGION, JSON.stringify({ + "by_region": false, + "region_direction": current_direction + })); + } + } + else { + // Sort column has changed to by function or class, remember that. + localStorage.setItem(coverage.SORTED_BY_REGION, JSON.stringify({ + "by_region": true, + "region_direction": direction + })); + } +} + +// Find all the elements with data-shortcut attribute, and use them to assign a shortcut key. +coverage.assign_shortkeys = function () { + document.querySelectorAll("[data-shortcut]").forEach(element => { + document.addEventListener("keypress", event => { + if (event.target.tagName.toLowerCase() === "input") { + return; // ignore keypress from search filter + } + if (event.key === element.dataset.shortcut) { + element.click(); + } + }); + }); +}; + +// Create the events for the filter box. +coverage.wire_up_filter = function () { + // Populate the filter and hide100 inputs if there are saved values for them. + const saved_filter_value = localStorage.getItem(coverage.FILTER_STORAGE); + if (saved_filter_value) { + document.getElementById("filter").value = saved_filter_value; + } + const saved_hide100_value = localStorage.getItem(coverage.HIDE100_STORAGE); + if (saved_hide100_value) { + document.getElementById("hide100").checked = JSON.parse(saved_hide100_value); + } + + // Cache elements. + const table = document.querySelector("table.index"); + const table_body_rows = table.querySelectorAll("tbody tr"); + const no_rows = document.getElementById("no_rows"); + + // Observe filter keyevents. + const filter_handler = (event => { + // Keep running total of each metric, first index contains number of shown rows + const totals = new Array(table.rows[0].cells.length).fill(0); + // Accumulate the percentage as fraction + totals[totals.length - 1] = { "numer": 0, "denom": 0 }; // nosemgrep: eslint.detect-object-injection + + var text = document.getElementById("filter").value; + // Store filter value + localStorage.setItem(coverage.FILTER_STORAGE, text); + const casefold = (text === text.toLowerCase()); + const hide100 = document.getElementById("hide100").checked; + // Store hide value. + localStorage.setItem(coverage.HIDE100_STORAGE, JSON.stringify(hide100)); + + // Hide / show elements. + table_body_rows.forEach(row => { + var show = false; + // Check the text filter. + for (let column = 0; column < totals.length; column++) { + cell = row.cells[column]; + if (cell.classList.contains("name")) { + var celltext = cell.textContent; + if (casefold) { + celltext = celltext.toLowerCase(); + } + if (celltext.includes(text)) { + show = true; + } + } + } + + // Check the "hide covered" filter. + if (show && hide100) { + const [numer, denom] = row.cells[row.cells.length - 1].dataset.ratio.split(" "); + show = (numer !== denom); + } + + if (!show) { + // hide + row.classList.add("hidden"); + return; + } + + // show + row.classList.remove("hidden"); + totals[0]++; + + for (let column = 0; column < totals.length; column++) { + // Accumulate dynamic totals + cell = row.cells[column] // nosemgrep: eslint.detect-object-injection + if (cell.classList.contains("name")) { + continue; + } + if (column === totals.length - 1) { + // Last column contains percentage + const [numer, denom] = cell.dataset.ratio.split(" "); + totals[column]["numer"] += parseInt(numer, 10); // nosemgrep: eslint.detect-object-injection + totals[column]["denom"] += parseInt(denom, 10); // nosemgrep: eslint.detect-object-injection + } + else { + totals[column] += parseInt(cell.textContent, 10); // nosemgrep: eslint.detect-object-injection + } + } + }); + + // Show placeholder if no rows will be displayed. + if (!totals[0]) { + // Show placeholder, hide table. + no_rows.style.display = "block"; + table.style.display = "none"; + return; + } + + // Hide placeholder, show table. + no_rows.style.display = null; + table.style.display = null; + + const footer = table.tFoot.rows[0]; + // Calculate new dynamic sum values based on visible rows. + for (let column = 0; column < totals.length; column++) { + // Get footer cell element. + const cell = footer.cells[column]; // nosemgrep: eslint.detect-object-injection + if (cell.classList.contains("name")) { + continue; + } + + // Set value into dynamic footer cell element. + if (column === totals.length - 1) { + // Percentage column uses the numerator and denominator, + // and adapts to the number of decimal places. + const match = /\.([0-9]+)/.exec(cell.textContent); + const places = match ? match[1].length : 0; + const { numer, denom } = totals[column]; // nosemgrep: eslint.detect-object-injection + cell.dataset.ratio = `${numer} ${denom}`; + // Check denom to prevent NaN if filtered files contain no statements + cell.textContent = denom + ? `${(numer * 100 / denom).toFixed(places)}%` + : `${(100).toFixed(places)}%`; + } + else { + cell.textContent = totals[column]; // nosemgrep: eslint.detect-object-injection + } + } + }); + + document.getElementById("filter").addEventListener("input", debounce(filter_handler)); + document.getElementById("hide100").addEventListener("input", debounce(filter_handler)); + + // Trigger change event on setup, to force filter on page refresh + // (filter value may still be present). + document.getElementById("filter").dispatchEvent(new Event("input")); + document.getElementById("hide100").dispatchEvent(new Event("input")); +}; +coverage.FILTER_STORAGE = "COVERAGE_FILTER_VALUE"; +coverage.HIDE100_STORAGE = "COVERAGE_HIDE100_VALUE"; + +// Set up the click-to-sort columns. +coverage.wire_up_sorting = function () { + document.querySelectorAll("[data-sortable] th[aria-sort]").forEach( + th => th.addEventListener("click", e => sortColumn(e.target)) + ); + + // Look for a localStorage item containing previous sort settings: + let th_id = "file", direction = "ascending"; + const stored_list = localStorage.getItem(coverage.INDEX_SORT_STORAGE); + if (stored_list) { + ({th_id, direction} = JSON.parse(stored_list)); + } + let by_region = false, region_direction = "ascending"; + const sorted_by_region = localStorage.getItem(coverage.SORTED_BY_REGION); + if (sorted_by_region) { + ({ + by_region, + region_direction + } = JSON.parse(sorted_by_region)); + } + + const region_id = "region"; + if (by_region && document.getElementById(region_id)) { + direction = region_direction; + } + // If we are in a page that has a column with id of "region", sort on + // it if the last sort was by function or class. + let th; + if (document.getElementById(region_id)) { + th = document.getElementById(by_region ? region_id : th_id); + } + else { + th = document.getElementById(th_id); + } + th.setAttribute("aria-sort", direction === "ascending" ? "descending" : "ascending"); + th.click() +}; + +coverage.INDEX_SORT_STORAGE = "COVERAGE_INDEX_SORT_2"; +coverage.SORTED_BY_REGION = "COVERAGE_SORT_REGION"; + +// Loaded on index.html +coverage.index_ready = function () { + coverage.assign_shortkeys(); + coverage.wire_up_filter(); + coverage.wire_up_sorting(); + + on_click(".button_prev_file", coverage.to_prev_file); + on_click(".button_next_file", coverage.to_next_file); + + on_click(".button_show_hide_help", coverage.show_hide_help); +}; + +// -- pyfile stuff -- + +coverage.LINE_FILTERS_STORAGE = "COVERAGE_LINE_FILTERS"; + +coverage.pyfile_ready = function () { + // If we're directed to a particular line number, highlight the line. + var frag = location.hash; + if (frag.length > 2 && frag[1] === "t") { + document.querySelector(frag).closest(".n").classList.add("highlight"); + coverage.set_sel(parseInt(frag.substr(2), 10)); + } + else { + coverage.set_sel(0); + } + + on_click(".button_toggle_run", coverage.toggle_lines); + on_click(".button_toggle_mis", coverage.toggle_lines); + on_click(".button_toggle_exc", coverage.toggle_lines); + on_click(".button_toggle_par", coverage.toggle_lines); + + on_click(".button_next_chunk", coverage.to_next_chunk_nicely); + on_click(".button_prev_chunk", coverage.to_prev_chunk_nicely); + on_click(".button_top_of_page", coverage.to_top); + on_click(".button_first_chunk", coverage.to_first_chunk); + + on_click(".button_prev_file", coverage.to_prev_file); + on_click(".button_next_file", coverage.to_next_file); + on_click(".button_to_index", coverage.to_index); + + on_click(".button_show_hide_help", coverage.show_hide_help); + + coverage.filters = undefined; + try { + coverage.filters = localStorage.getItem(coverage.LINE_FILTERS_STORAGE); + } catch(err) {} + + if (coverage.filters) { + coverage.filters = JSON.parse(coverage.filters); + } + else { + coverage.filters = {run: false, exc: true, mis: true, par: true}; + } + + for (cls in coverage.filters) { + coverage.set_line_visibilty(cls, coverage.filters[cls]); // nosemgrep: eslint.detect-object-injection + } + + coverage.assign_shortkeys(); + coverage.init_scroll_markers(); + coverage.wire_up_sticky_header(); + + document.querySelectorAll("[id^=ctxs]").forEach( + cbox => cbox.addEventListener("click", coverage.expand_contexts) + ); + + // Rebuild scroll markers when the window height changes. + window.addEventListener("resize", coverage.build_scroll_markers); +}; + +coverage.toggle_lines = function (event) { + const btn = event.target.closest("button"); + const category = btn.value + const show = !btn.classList.contains("show_" + category); + coverage.set_line_visibilty(category, show); + coverage.build_scroll_markers(); + coverage.filters[category] = show; + try { + localStorage.setItem(coverage.LINE_FILTERS_STORAGE, JSON.stringify(coverage.filters)); + } catch(err) {} +}; + +coverage.set_line_visibilty = function (category, should_show) { + const cls = "show_" + category; + const btn = document.querySelector(".button_toggle_" + category); + if (btn) { + if (should_show) { + document.querySelectorAll("#source ." + category).forEach(e => e.classList.add(cls)); + btn.classList.add(cls); + } + else { + document.querySelectorAll("#source ." + category).forEach(e => e.classList.remove(cls)); + btn.classList.remove(cls); + } + } +}; + +// Return the nth line div. +coverage.line_elt = function (n) { + return document.getElementById("t" + n)?.closest("p"); +}; + +// Set the selection. b and e are line numbers. +coverage.set_sel = function (b, e) { + // The first line selected. + coverage.sel_begin = b; + // The next line not selected. + coverage.sel_end = (e === undefined) ? b+1 : e; +}; + +coverage.to_top = function () { + coverage.set_sel(0, 1); + coverage.scroll_window(0); +}; + +coverage.to_first_chunk = function () { + coverage.set_sel(0, 1); + coverage.to_next_chunk(); +}; + +coverage.to_prev_file = function () { + window.location = document.getElementById("prevFileLink").href; +} + +coverage.to_next_file = function () { + window.location = document.getElementById("nextFileLink").href; +} + +coverage.to_index = function () { + location.href = document.getElementById("indexLink").href; +} + +coverage.show_hide_help = function () { + const helpCheck = document.getElementById("help_panel_state") + helpCheck.checked = !helpCheck.checked; +} + +// Return a string indicating what kind of chunk this line belongs to, +// or null if not a chunk. +coverage.chunk_indicator = function (line_elt) { + const classes = line_elt?.className; + if (!classes) { + return null; + } + const match = classes.match(/\bshow_\w+\b/); + if (!match) { + return null; + } + return match[0]; +}; + +coverage.to_next_chunk = function () { + const c = coverage; + + // Find the start of the next colored chunk. + var probe = c.sel_end; + var chunk_indicator, probe_line; + while (true) { + probe_line = c.line_elt(probe); + if (!probe_line) { + return; + } + chunk_indicator = c.chunk_indicator(probe_line); + if (chunk_indicator) { + break; + } + probe++; + } + + // There's a next chunk, `probe` points to it. + var begin = probe; + + // Find the end of this chunk. + var next_indicator = chunk_indicator; + while (next_indicator === chunk_indicator) { + probe++; + probe_line = c.line_elt(probe); + next_indicator = c.chunk_indicator(probe_line); + } + c.set_sel(begin, probe); + c.show_selection(); +}; + +coverage.to_prev_chunk = function () { + const c = coverage; + + // Find the end of the prev colored chunk. + var probe = c.sel_begin-1; + var probe_line = c.line_elt(probe); + if (!probe_line) { + return; + } + var chunk_indicator = c.chunk_indicator(probe_line); + while (probe > 1 && !chunk_indicator) { + probe--; + probe_line = c.line_elt(probe); + if (!probe_line) { + return; + } + chunk_indicator = c.chunk_indicator(probe_line); + } + + // There's a prev chunk, `probe` points to its last line. + var end = probe+1; + + // Find the beginning of this chunk. + var prev_indicator = chunk_indicator; + while (prev_indicator === chunk_indicator) { + probe--; + if (probe <= 0) { + return; + } + probe_line = c.line_elt(probe); + prev_indicator = c.chunk_indicator(probe_line); + } + c.set_sel(probe+1, end); + c.show_selection(); +}; + +// Returns 0, 1, or 2: how many of the two ends of the selection are on +// the screen right now? +coverage.selection_ends_on_screen = function () { + if (coverage.sel_begin === 0) { + return 0; + } + + const begin = coverage.line_elt(coverage.sel_begin); + const end = coverage.line_elt(coverage.sel_end-1); + + return ( + (checkVisible(begin) ? 1 : 0) + + (checkVisible(end) ? 1 : 0) + ); +}; + +coverage.to_next_chunk_nicely = function () { + if (coverage.selection_ends_on_screen() === 0) { + // The selection is entirely off the screen: + // Set the top line on the screen as selection. + + // This will select the top-left of the viewport + // As this is most likely the span with the line number we take the parent + const line = document.elementFromPoint(0, 0).parentElement; + if (line.parentElement !== document.getElementById("source")) { + // The element is not a source line but the header or similar + coverage.select_line_or_chunk(1); + } + else { + // We extract the line number from the id + coverage.select_line_or_chunk(parseInt(line.id.substring(1), 10)); + } + } + coverage.to_next_chunk(); +}; + +coverage.to_prev_chunk_nicely = function () { + if (coverage.selection_ends_on_screen() === 0) { + // The selection is entirely off the screen: + // Set the lowest line on the screen as selection. + + // This will select the bottom-left of the viewport + // As this is most likely the span with the line number we take the parent + const line = document.elementFromPoint(document.documentElement.clientHeight-1, 0).parentElement; + if (line.parentElement !== document.getElementById("source")) { + // The element is not a source line but the header or similar + coverage.select_line_or_chunk(coverage.lines_len); + } + else { + // We extract the line number from the id + coverage.select_line_or_chunk(parseInt(line.id.substring(1), 10)); + } + } + coverage.to_prev_chunk(); +}; + +// Select line number lineno, or if it is in a colored chunk, select the +// entire chunk +coverage.select_line_or_chunk = function (lineno) { + var c = coverage; + var probe_line = c.line_elt(lineno); + if (!probe_line) { + return; + } + var the_indicator = c.chunk_indicator(probe_line); + if (the_indicator) { + // The line is in a highlighted chunk. + // Search backward for the first line. + var probe = lineno; + var indicator = the_indicator; + while (probe > 0 && indicator === the_indicator) { + probe--; + probe_line = c.line_elt(probe); + if (!probe_line) { + break; + } + indicator = c.chunk_indicator(probe_line); + } + var begin = probe + 1; + + // Search forward for the last line. + probe = lineno; + indicator = the_indicator; + while (indicator === the_indicator) { + probe++; + probe_line = c.line_elt(probe); + indicator = c.chunk_indicator(probe_line); + } + + coverage.set_sel(begin, probe); + } + else { + coverage.set_sel(lineno); + } +}; + +coverage.show_selection = function () { + // Highlight the lines in the chunk + document.querySelectorAll("#source .highlight").forEach(e => e.classList.remove("highlight")); + for (let probe = coverage.sel_begin; probe < coverage.sel_end; probe++) { + coverage.line_elt(probe).querySelector(".n").classList.add("highlight"); + } + + coverage.scroll_to_selection(); +}; + +coverage.scroll_to_selection = function () { + // Scroll the page if the chunk isn't fully visible. + if (coverage.selection_ends_on_screen() < 2) { + const element = coverage.line_elt(coverage.sel_begin); + coverage.scroll_window(element.offsetTop - 60); + } +}; + +coverage.scroll_window = function (to_pos) { + window.scroll({top: to_pos, behavior: "smooth"}); +}; + +coverage.init_scroll_markers = function () { + // Init some variables + coverage.lines_len = document.querySelectorAll("#source > p").length; + + // Build html + coverage.build_scroll_markers(); +}; + +coverage.build_scroll_markers = function () { + const temp_scroll_marker = document.getElementById("scroll_marker") + if (temp_scroll_marker) temp_scroll_marker.remove(); + // Don't build markers if the window has no scroll bar. + if (document.body.scrollHeight <= window.innerHeight) { + return; + } + + const marker_scale = window.innerHeight / document.body.scrollHeight; + const line_height = Math.min(Math.max(3, window.innerHeight / coverage.lines_len), 10); + + let previous_line = -99, last_mark, last_top; + + const scroll_marker = document.createElement("div"); + scroll_marker.id = "scroll_marker"; + document.getElementById("source").querySelectorAll( + "p.show_run, p.show_mis, p.show_exc, p.show_exc, p.show_par" + ).forEach(element => { + const line_top = Math.floor(element.offsetTop * marker_scale); + const line_number = parseInt(element.querySelector(".n a").id.substr(1)); + + if (line_number === previous_line + 1) { + // If this solid missed block just make previous mark higher. + last_mark.style.height = `${line_top + line_height - last_top}px`; + } + else { + // Add colored line in scroll_marker block. + last_mark = document.createElement("div"); + last_mark.id = `m${line_number}`; + last_mark.classList.add("marker"); + last_mark.style.height = `${line_height}px`; + last_mark.style.top = `${line_top}px`; + scroll_marker.append(last_mark); + last_top = line_top; + } + + previous_line = line_number; + }); + + // Append last to prevent layout calculation + document.body.append(scroll_marker); +}; + +coverage.wire_up_sticky_header = function () { + const header = document.querySelector("header"); + const header_bottom = ( + header.querySelector(".content h2").getBoundingClientRect().top - + header.getBoundingClientRect().top + ); + + function updateHeader() { + if (window.scrollY > header_bottom) { + header.classList.add("sticky"); + } + else { + header.classList.remove("sticky"); + } + } + + window.addEventListener("scroll", updateHeader); + updateHeader(); +}; + +coverage.expand_contexts = function (e) { + var ctxs = e.target.parentNode.querySelector(".ctxs"); + + if (!ctxs.classList.contains("expanded")) { + var ctxs_text = ctxs.textContent; + var width = Number(ctxs_text[0]); + ctxs.textContent = ""; + for (var i = 1; i < ctxs_text.length; i += width) { + key = ctxs_text.substring(i, i + width).trim(); + ctxs.appendChild(document.createTextNode(contexts[key])); + ctxs.appendChild(document.createElement("br")); + } + ctxs.classList.add("expanded"); + } +}; + +document.addEventListener("DOMContentLoaded", () => { + if (document.body.classList.contains("indexfile")) { + coverage.index_ready(); + } + else { + coverage.pyfile_ready(); + } +}); diff --git a/htmlcov/favicon_32_cb_58284776.png b/htmlcov/favicon_32_cb_58284776.png new file mode 100644 index 0000000..8649f04 Binary files /dev/null and b/htmlcov/favicon_32_cb_58284776.png differ diff --git a/htmlcov/function_index.html b/htmlcov/function_index.html new file mode 100644 index 0000000..8c2c993 --- /dev/null +++ b/htmlcov/function_index.html @@ -0,0 +1,347 @@ + + + + + Coverage report + + + + + +
+
+

Coverage report: + 96% +

+ +
+ +
+ + +
+
+

+ Files + Functions + Classes +

+

+ coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Filefunctionstatementsmissingexcludedcoverage
app\__init__.py(no function)000100%
app\domain\__init__.py(no function)000100%
app\domain\models.pygenerate_uuid100100%
app\domain\models.pyChat.update_conversation100100%
app\domain\models.pyChat.get_conversation_history100100%
app\domain\models.py(no function)1200100%
app\domain\ports.pyChatRepository.save_chat1100%
app\domain\ports.pyChatRepository.get_chat1100%
app\domain\ports.pyAgentPort.__call__1100%
app\domain\ports.pyAgentPort.get_conversation_history1100%
app\domain\ports.pyAgentPort.set_memory_variables1100%
app\domain\ports.pyAgentPort.get_last_response1100%
app\domain\ports.pyTranscriptionPort.transcribe_audio1100%
app\domain\ports.py(no function)2200100%
app\logs.pyget_lambda_logger800100%
app\logs.py(no function)600100%
app\services\__init__.py(no function)000100%
app\services\usecases.pyChatService.__init__300100%
app\services\usecases.pyChatService.start_conversation500100%
app\services\usecases.pyChatService.continue_conversation1200100%
app\services\usecases.pyChatService._update_chat300100%
app\services\usecases.py(no function)1100100%
test\__init__.py(no function)000100%
test\test2.pytest_update_chat1400100%
test\test2.pytest_continue_conversation_with_query1300100%
test\test2.pytest_continue_conversation_with_voice_file1500100%
test\test2.pytest_continue_conversation_no_input700100%
test\test2.pytest_continue_conversation_chat_not_found800100%
test\test2.pytest_start_conversation1300100%
test\test2.py(no function)1400100%
Total 1767096%
+

+ No items found using the specified filter. +

+
+ + + diff --git a/htmlcov/index.html b/htmlcov/index.html new file mode 100644 index 0000000..3b6fb11 --- /dev/null +++ b/htmlcov/index.html @@ -0,0 +1,167 @@ + + + + + Coverage report + + + + + +
+
+

Coverage report: + 96% +

+ +
+ +
+ + +
+
+

+ Files + Functions + Classes +

+

+ coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Filestatementsmissingexcludedcoverage
app\__init__.py000100%
app\domain\__init__.py000100%
app\domain\models.py1500100%
app\domain\ports.py297076%
app\logs.py1400100%
app\services\__init__.py000100%
app\services\usecases.py3400100%
test\__init__.py000100%
test\test2.py8400100%
Total1767096%
+

+ No items found using the specified filter. +

+
+ + + diff --git a/htmlcov/keybd_closed_cb_ce680311.png b/htmlcov/keybd_closed_cb_ce680311.png new file mode 100644 index 0000000..ba119c4 Binary files /dev/null and b/htmlcov/keybd_closed_cb_ce680311.png differ diff --git a/htmlcov/status.json b/htmlcov/status.json new file mode 100644 index 0000000..8dff024 --- /dev/null +++ b/htmlcov/status.json @@ -0,0 +1 @@ +{"note":"This file is an internal implementation detail to speed up HTML report generation. Its format can change at any time. You might be looking for the JSON report: https://coverage.rtfd.io/cmd.html#cmd-json","format":5,"version":"7.6.1","globals":"d242b16b0bae35c70b0ee4de6f54ade7","files":{"z_5f5a17c013354698___init___py":{"hash":"e6baa73cda2916dad605215f937a92e1","index":{"url":"z_5f5a17c013354698___init___py.html","file":"app\\__init__.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":0,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_ad0ff7ef6dee06c8___init___py":{"hash":"e6baa73cda2916dad605215f937a92e1","index":{"url":"z_ad0ff7ef6dee06c8___init___py.html","file":"app\\domain\\__init__.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":0,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_ad0ff7ef6dee06c8_models_py":{"hash":"8ecfa145a14429b0337d4755a6dae981","index":{"url":"z_ad0ff7ef6dee06c8_models_py.html","file":"app\\domain\\models.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":15,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_ad0ff7ef6dee06c8_ports_py":{"hash":"534360cc7a956afc0a4488ccaf58f8fe","index":{"url":"z_ad0ff7ef6dee06c8_ports_py.html","file":"app\\domain\\ports.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":29,"n_excluded":0,"n_missing":7,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_5f5a17c013354698_logs_py":{"hash":"98c10fc254bdf9949b38279db20d4f99","index":{"url":"z_5f5a17c013354698_logs_py.html","file":"app\\logs.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":14,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_4c37ce8615b5aa70___init___py":{"hash":"e6baa73cda2916dad605215f937a92e1","index":{"url":"z_4c37ce8615b5aa70___init___py.html","file":"app\\services\\__init__.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":0,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_4c37ce8615b5aa70_usecases_py":{"hash":"6ebb7e754af3c5d9cf55ade0bcf3da6b","index":{"url":"z_4c37ce8615b5aa70_usecases_py.html","file":"app\\services\\usecases.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":34,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_36f028580bb02cc8___init___py":{"hash":"e6baa73cda2916dad605215f937a92e1","index":{"url":"z_36f028580bb02cc8___init___py.html","file":"test\\__init__.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":0,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_36f028580bb02cc8_test_py":{"hash":"e132be59711be171f1d0e764a596438d","index":{"url":"z_36f028580bb02cc8_test_py.html","file":"test\\test.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":15,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}},"z_36f028580bb02cc8_test2_py":{"hash":"81e0d9b99748aa135f01438dc135c736","index":{"url":"z_36f028580bb02cc8_test2_py.html","file":"test\\test2.py","description":"","nums":{"precision":0,"n_files":1,"n_statements":84,"n_excluded":0,"n_missing":0,"n_branches":0,"n_partial_branches":0,"n_missing_branches":0}}}}} \ No newline at end of file diff --git a/htmlcov/style_cb_718ce007.css b/htmlcov/style_cb_718ce007.css new file mode 100644 index 0000000..3cdaf05 --- /dev/null +++ b/htmlcov/style_cb_718ce007.css @@ -0,0 +1,337 @@ +@charset "UTF-8"; +/* Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 */ +/* For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt */ +/* Don't edit this .css file. Edit the .scss file instead! */ +html, body, h1, h2, h3, p, table, td, th { margin: 0; padding: 0; border: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline; } + +body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; font-size: 1em; background: #fff; color: #000; } + +@media (prefers-color-scheme: dark) { body { background: #1e1e1e; } } + +@media (prefers-color-scheme: dark) { body { color: #eee; } } + +html > body { font-size: 16px; } + +a:active, a:focus { outline: 2px dashed #007acc; } + +p { font-size: .875em; line-height: 1.4em; } + +table { border-collapse: collapse; } + +td { vertical-align: top; } + +table tr.hidden { display: none !important; } + +p#no_rows { display: none; font-size: 1.15em; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } + +a.nav { text-decoration: none; color: inherit; } + +a.nav:hover { text-decoration: underline; color: inherit; } + +.hidden { display: none; } + +header { background: #f8f8f8; width: 100%; z-index: 2; border-bottom: 1px solid #ccc; } + +@media (prefers-color-scheme: dark) { header { background: black; } } + +@media (prefers-color-scheme: dark) { header { border-color: #333; } } + +header .content { padding: 1rem 3.5rem; } + +header h2 { margin-top: .5em; font-size: 1em; } + +header h2 a.button { font-family: inherit; font-size: inherit; border: 1px solid; border-radius: .2em; background: #eee; color: inherit; text-decoration: none; padding: .1em .5em; margin: 1px calc(.1em + 1px); cursor: pointer; border-color: #ccc; } + +@media (prefers-color-scheme: dark) { header h2 a.button { background: #333; } } + +@media (prefers-color-scheme: dark) { header h2 a.button { border-color: #444; } } + +header h2 a.button.current { border: 2px solid; background: #fff; border-color: #999; cursor: default; } + +@media (prefers-color-scheme: dark) { header h2 a.button.current { background: #1e1e1e; } } + +@media (prefers-color-scheme: dark) { header h2 a.button.current { border-color: #777; } } + +header p.text { margin: .5em 0 -.5em; color: #666; font-style: italic; } + +@media (prefers-color-scheme: dark) { header p.text { color: #aaa; } } + +header.sticky { position: fixed; left: 0; right: 0; height: 2.5em; } + +header.sticky .text { display: none; } + +header.sticky h1, header.sticky h2 { font-size: 1em; margin-top: 0; display: inline-block; } + +header.sticky .content { padding: 0.5rem 3.5rem; } + +header.sticky .content p { font-size: 1em; } + +header.sticky ~ #source { padding-top: 6.5em; } + +main { position: relative; z-index: 1; } + +footer { margin: 1rem 3.5rem; } + +footer .content { padding: 0; color: #666; font-style: italic; } + +@media (prefers-color-scheme: dark) { footer .content { color: #aaa; } } + +#index { margin: 1rem 0 0 3.5rem; } + +h1 { font-size: 1.25em; display: inline-block; } + +#filter_container { float: right; margin: 0 2em 0 0; line-height: 1.66em; } + +#filter_container #filter { width: 10em; padding: 0.2em 0.5em; border: 2px solid #ccc; background: #fff; color: #000; } + +@media (prefers-color-scheme: dark) { #filter_container #filter { border-color: #444; } } + +@media (prefers-color-scheme: dark) { #filter_container #filter { background: #1e1e1e; } } + +@media (prefers-color-scheme: dark) { #filter_container #filter { color: #eee; } } + +#filter_container #filter:focus { border-color: #007acc; } + +#filter_container :disabled ~ label { color: #ccc; } + +@media (prefers-color-scheme: dark) { #filter_container :disabled ~ label { color: #444; } } + +#filter_container label { font-size: .875em; color: #666; } + +@media (prefers-color-scheme: dark) { #filter_container label { color: #aaa; } } + +header button { font-family: inherit; font-size: inherit; border: 1px solid; border-radius: .2em; background: #eee; color: inherit; text-decoration: none; padding: .1em .5em; margin: 1px calc(.1em + 1px); cursor: pointer; border-color: #ccc; } + +@media (prefers-color-scheme: dark) { header button { background: #333; } } + +@media (prefers-color-scheme: dark) { header button { border-color: #444; } } + +header button:active, header button:focus { outline: 2px dashed #007acc; } + +header button.run { background: #eeffee; } + +@media (prefers-color-scheme: dark) { header button.run { background: #373d29; } } + +header button.run.show_run { background: #dfd; border: 2px solid #00dd00; margin: 0 .1em; } + +@media (prefers-color-scheme: dark) { header button.run.show_run { background: #373d29; } } + +header button.mis { background: #ffeeee; } + +@media (prefers-color-scheme: dark) { header button.mis { background: #4b1818; } } + +header button.mis.show_mis { background: #fdd; border: 2px solid #ff0000; margin: 0 .1em; } + +@media (prefers-color-scheme: dark) { header button.mis.show_mis { background: #4b1818; } } + +header button.exc { background: #f7f7f7; } + +@media (prefers-color-scheme: dark) { header button.exc { background: #333; } } + +header button.exc.show_exc { background: #eee; border: 2px solid #808080; margin: 0 .1em; } + +@media (prefers-color-scheme: dark) { header button.exc.show_exc { background: #333; } } + +header button.par { background: #ffffd5; } + +@media (prefers-color-scheme: dark) { header button.par { background: #650; } } + +header button.par.show_par { background: #ffa; border: 2px solid #bbbb00; margin: 0 .1em; } + +@media (prefers-color-scheme: dark) { header button.par.show_par { background: #650; } } + +#help_panel, #source p .annotate.long { display: none; position: absolute; z-index: 999; background: #ffffcc; border: 1px solid #888; border-radius: .2em; color: #333; padding: .25em .5em; } + +#source p .annotate.long { white-space: normal; float: right; top: 1.75em; right: 1em; height: auto; } + +#help_panel_wrapper { float: right; position: relative; } + +#keyboard_icon { margin: 5px; } + +#help_panel_state { display: none; } + +#help_panel { top: 25px; right: 0; padding: .75em; border: 1px solid #883; color: #333; } + +#help_panel .keyhelp p { margin-top: .75em; } + +#help_panel .legend { font-style: italic; margin-bottom: 1em; } + +.indexfile #help_panel { width: 25em; } + +.pyfile #help_panel { width: 18em; } + +#help_panel_state:checked ~ #help_panel { display: block; } + +kbd { border: 1px solid black; border-color: #888 #333 #333 #888; padding: .1em .35em; font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-weight: bold; background: #eee; border-radius: 3px; } + +#source { padding: 1em 0 1em 3.5rem; font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; } + +#source p { position: relative; white-space: pre; } + +#source p * { box-sizing: border-box; } + +#source p .n { float: left; text-align: right; width: 3.5rem; box-sizing: border-box; margin-left: -3.5rem; padding-right: 1em; color: #999; user-select: none; } + +@media (prefers-color-scheme: dark) { #source p .n { color: #777; } } + +#source p .n.highlight { background: #ffdd00; } + +#source p .n a { scroll-margin-top: 6em; text-decoration: none; color: #999; } + +@media (prefers-color-scheme: dark) { #source p .n a { color: #777; } } + +#source p .n a:hover { text-decoration: underline; color: #999; } + +@media (prefers-color-scheme: dark) { #source p .n a:hover { color: #777; } } + +#source p .t { display: inline-block; width: 100%; box-sizing: border-box; margin-left: -.5em; padding-left: 0.3em; border-left: 0.2em solid #fff; } + +@media (prefers-color-scheme: dark) { #source p .t { border-color: #1e1e1e; } } + +#source p .t:hover { background: #f2f2f2; } + +@media (prefers-color-scheme: dark) { #source p .t:hover { background: #282828; } } + +#source p .t:hover ~ .r .annotate.long { display: block; } + +#source p .t .com { color: #008000; font-style: italic; line-height: 1px; } + +@media (prefers-color-scheme: dark) { #source p .t .com { color: #6a9955; } } + +#source p .t .key { font-weight: bold; line-height: 1px; } + +#source p .t .str { color: #0451a5; } + +@media (prefers-color-scheme: dark) { #source p .t .str { color: #9cdcfe; } } + +#source p.mis .t { border-left: 0.2em solid #ff0000; } + +#source p.mis.show_mis .t { background: #fdd; } + +@media (prefers-color-scheme: dark) { #source p.mis.show_mis .t { background: #4b1818; } } + +#source p.mis.show_mis .t:hover { background: #f2d2d2; } + +@media (prefers-color-scheme: dark) { #source p.mis.show_mis .t:hover { background: #532323; } } + +#source p.run .t { border-left: 0.2em solid #00dd00; } + +#source p.run.show_run .t { background: #dfd; } + +@media (prefers-color-scheme: dark) { #source p.run.show_run .t { background: #373d29; } } + +#source p.run.show_run .t:hover { background: #d2f2d2; } + +@media (prefers-color-scheme: dark) { #source p.run.show_run .t:hover { background: #404633; } } + +#source p.exc .t { border-left: 0.2em solid #808080; } + +#source p.exc.show_exc .t { background: #eee; } + +@media (prefers-color-scheme: dark) { #source p.exc.show_exc .t { background: #333; } } + +#source p.exc.show_exc .t:hover { background: #e2e2e2; } + +@media (prefers-color-scheme: dark) { #source p.exc.show_exc .t:hover { background: #3c3c3c; } } + +#source p.par .t { border-left: 0.2em solid #bbbb00; } + +#source p.par.show_par .t { background: #ffa; } + +@media (prefers-color-scheme: dark) { #source p.par.show_par .t { background: #650; } } + +#source p.par.show_par .t:hover { background: #f2f2a2; } + +@media (prefers-color-scheme: dark) { #source p.par.show_par .t:hover { background: #6d5d0c; } } + +#source p .r { position: absolute; top: 0; right: 2.5em; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } + +#source p .annotate { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; color: #666; padding-right: .5em; } + +@media (prefers-color-scheme: dark) { #source p .annotate { color: #ddd; } } + +#source p .annotate.short:hover ~ .long { display: block; } + +#source p .annotate.long { width: 30em; right: 2.5em; } + +#source p input { display: none; } + +#source p input ~ .r label.ctx { cursor: pointer; border-radius: .25em; } + +#source p input ~ .r label.ctx::before { content: "▶ "; } + +#source p input ~ .r label.ctx:hover { background: #e8f4ff; color: #666; } + +@media (prefers-color-scheme: dark) { #source p input ~ .r label.ctx:hover { background: #0f3a42; } } + +@media (prefers-color-scheme: dark) { #source p input ~ .r label.ctx:hover { color: #aaa; } } + +#source p input:checked ~ .r label.ctx { background: #d0e8ff; color: #666; border-radius: .75em .75em 0 0; padding: 0 .5em; margin: -.25em 0; } + +@media (prefers-color-scheme: dark) { #source p input:checked ~ .r label.ctx { background: #056; } } + +@media (prefers-color-scheme: dark) { #source p input:checked ~ .r label.ctx { color: #aaa; } } + +#source p input:checked ~ .r label.ctx::before { content: "▼ "; } + +#source p input:checked ~ .ctxs { padding: .25em .5em; overflow-y: scroll; max-height: 10.5em; } + +#source p label.ctx { color: #999; display: inline-block; padding: 0 .5em; font-size: .8333em; } + +@media (prefers-color-scheme: dark) { #source p label.ctx { color: #777; } } + +#source p .ctxs { display: block; max-height: 0; overflow-y: hidden; transition: all .2s; padding: 0 .5em; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; white-space: nowrap; background: #d0e8ff; border-radius: .25em; margin-right: 1.75em; text-align: right; } + +@media (prefers-color-scheme: dark) { #source p .ctxs { background: #056; } } + +#index { font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 0.875em; } + +#index table.index { margin-left: -.5em; } + +#index td, #index th { text-align: right; padding: .25em .5em; border-bottom: 1px solid #eee; } + +@media (prefers-color-scheme: dark) { #index td, #index th { border-color: #333; } } + +#index td.name, #index th.name { text-align: left; width: auto; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; min-width: 15em; } + +#index th { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; font-style: italic; color: #333; cursor: pointer; } + +@media (prefers-color-scheme: dark) { #index th { color: #ddd; } } + +#index th:hover { background: #eee; } + +@media (prefers-color-scheme: dark) { #index th:hover { background: #333; } } + +#index th .arrows { color: #666; font-size: 85%; font-family: sans-serif; font-style: normal; pointer-events: none; } + +#index th[aria-sort="ascending"], #index th[aria-sort="descending"] { white-space: nowrap; background: #eee; padding-left: .5em; } + +@media (prefers-color-scheme: dark) { #index th[aria-sort="ascending"], #index th[aria-sort="descending"] { background: #333; } } + +#index th[aria-sort="ascending"] .arrows::after { content: " ▲"; } + +#index th[aria-sort="descending"] .arrows::after { content: " ▼"; } + +#index td.name { font-size: 1.15em; } + +#index td.name a { text-decoration: none; color: inherit; } + +#index td.name .no-noun { font-style: italic; } + +#index tr.total td, #index tr.total_dynamic td { font-weight: bold; border-top: 1px solid #ccc; border-bottom: none; } + +#index tr.region:hover { background: #eee; } + +@media (prefers-color-scheme: dark) { #index tr.region:hover { background: #333; } } + +#index tr.region:hover td.name { text-decoration: underline; color: inherit; } + +#scroll_marker { position: fixed; z-index: 3; right: 0; top: 0; width: 16px; height: 100%; background: #fff; border-left: 1px solid #eee; will-change: transform; } + +@media (prefers-color-scheme: dark) { #scroll_marker { background: #1e1e1e; } } + +@media (prefers-color-scheme: dark) { #scroll_marker { border-color: #333; } } + +#scroll_marker .marker { background: #ccc; position: absolute; min-height: 3px; width: 100%; } + +@media (prefers-color-scheme: dark) { #scroll_marker .marker { background: #444; } } diff --git a/htmlcov/z_36f028580bb02cc8___init___py.html b/htmlcov/z_36f028580bb02cc8___init___py.html new file mode 100644 index 0000000..f9f8426 --- /dev/null +++ b/htmlcov/z_36f028580bb02cc8___init___py.html @@ -0,0 +1,97 @@ + + + + + Coverage for test\__init__.py: 100% + + + + + +
+
+

+ Coverage for test\__init__.py: + 100% +

+ +

+ 0 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-03 16:50 -0500 +

+ +
+
+
+
+ + + diff --git a/htmlcov/z_36f028580bb02cc8_test2_py.html b/htmlcov/z_36f028580bb02cc8_test2_py.html new file mode 100644 index 0000000..7645174 --- /dev/null +++ b/htmlcov/z_36f028580bb02cc8_test2_py.html @@ -0,0 +1,314 @@ + + + + + Coverage for test\test2.py: 100% + + + + + +
+
+

+ Coverage for test\test2.py: + 100% +

+ +

+ 84 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+ +
+
+
+

1# test_usecases.py ubicado en tests/services 

+

2 

+

3import pytest 

+

4from unittest.mock import Mock 

+

5from app.services.usecases import ChatService, InputNotProvided, NoChatFound 

+

6from app.domain import models 

+

7 

+

8 

+

9def test_update_chat(): 

+

10 # Crear un mock para el agente 

+

11 mock_agent = Mock() 

+

12 conversation_history = [ 

+

13 {"type": "human", "content": "Hola"}, 

+

14 {"type": "ai", "content": "Hola, ¿en qué puedo ayudarte?"} 

+

15 ] 

+

16 mock_agent.get_conversation_history.return_value = conversation_history 

+

17 

+

18 # Crear un mock para el repositorio de chats 

+

19 mock_db = Mock() 

+

20 

+

21 # Crear un mock para el transcriptor (aunque no se utiliza en esta prueba) 

+

22 mock_transcriber = Mock() 

+

23 

+

24 # Instanciar ChatService con los mocks 

+

25 chat_service = ChatService( 

+

26 agent=mock_agent, 

+

27 db=mock_db, 

+

28 transcriber=mock_transcriber 

+

29 ) 

+

30 

+

31 # Crear un objeto Chat de prueba 

+

32 chat = models.Chat(id="test_chat_id") 

+

33 

+

34 # Llamar al método _update_chat 

+

35 chat_service._update_chat(chat) 

+

36 

+

37 # Verificar que get_conversation_history fue llamado 

+

38 mock_agent.get_conversation_history.assert_called_once() 

+

39 

+

40 # Verificar que save_chat fue llamado con el chat actualizado 

+

41 expected_chat = models.Chat(id="test_chat_id") 

+

42 expected_chat.update_conversation(conversation_history) 

+

43 

+

44 # Obtener el chat que fue pasado a save_chat 

+

45 saved_chat = mock_db.save_chat.call_args[0][0] 

+

46 

+

47 # Assert para comprobar que el ID coincide 

+

48 assert saved_chat.id == expected_chat.id 

+

49 # Assert para comprobar que la conversación fue actualizada correctamente 

+

50 assert saved_chat.conversation.history == expected_chat.conversation.history 

+

51 

+

52 

+

53 

+

54 

+

55 

+

56def test_continue_conversation_with_query(): 

+

57 # Mocks de dependencias 

+

58 mock_agent = Mock() 

+

59 mock_agent.get_last_response.return_value = "Respuesta del agente" 

+

60 mock_db = Mock() 

+

61 mock_transcriber = Mock() 

+

62 

+

63 # Simular que el chat existe en la base de datos 

+

64 chat = models.Chat(id="test_chat_id") 

+

65 mock_db.get_chat.return_value = chat 

+

66 

+

67 # Instanciar el servicio 

+

68 chat_service = ChatService( 

+

69 agent=mock_agent, 

+

70 db=mock_db, 

+

71 transcriber=mock_transcriber 

+

72 ) 

+

73 

+

74 # Ejecutar el método con un query 

+

75 response = chat_service.continue_conversation( 

+

76 conversation_id="test_chat_id", 

+

77 query="Hola", 

+

78 voice_file=None 

+

79 ) 

+

80 

+

81 # Verificaciones 

+

82 mock_db.get_chat.assert_called_once_with("test_chat_id") 

+

83 mock_agent.set_memory_variables.assert_called_once_with(chat.get_conversation_history()) 

+

84 mock_agent.assert_called_once_with(query="Hola") 

+

85 mock_db.save_chat.assert_called_once() 

+

86 assert response == "Respuesta del agente" 

+

87 

+

88 

+

89def test_continue_conversation_with_voice_file(): 

+

90 # Mocks de dependencias 

+

91 mock_agent = Mock() 

+

92 mock_agent.get_last_response.return_value = "Respuesta del agente" 

+

93 mock_db = Mock() 

+

94 mock_transcriber = Mock() 

+

95 mock_transcriber.transcribe_audio.return_value = "Texto transcrito" 

+

96 

+

97 # Simular que el chat existe en la base de datos 

+

98 chat = models.Chat(id="test_chat_id") 

+

99 mock_db.get_chat.return_value = chat 

+

100 

+

101 # Instanciar el servicio 

+

102 chat_service = ChatService( 

+

103 agent=mock_agent, 

+

104 db=mock_db, 

+

105 transcriber=mock_transcriber 

+

106 ) 

+

107 

+

108 # Ejecutar el método con un voice_file 

+

109 response = chat_service.continue_conversation( 

+

110 conversation_id="test_chat_id", 

+

111 query=None, 

+

112 voice_file=b"archivo de audio" 

+

113 ) 

+

114 

+

115 # Verificaciones 

+

116 mock_transcriber.transcribe_audio.assert_called_once_with(b"archivo de audio") 

+

117 mock_db.get_chat.assert_called_once_with("test_chat_id") 

+

118 mock_agent.set_memory_variables.assert_called_once_with(chat.get_conversation_history()) 

+

119 mock_agent.assert_called_once_with(query="Texto transcrito") 

+

120 mock_db.save_chat.assert_called_once() 

+

121 assert response == "Respuesta del agente" 

+

122 

+

123 

+

124def test_continue_conversation_no_input(): 

+

125 # Mocks de dependencias 

+

126 mock_agent = Mock() 

+

127 mock_db = Mock() 

+

128 mock_transcriber = Mock() 

+

129 

+

130 # Instanciar el servicio 

+

131 chat_service = ChatService( 

+

132 agent=mock_agent, 

+

133 db=mock_db, 

+

134 transcriber=mock_transcriber 

+

135 ) 

+

136 

+

137 # Ejecutar el método sin query ni voice_file y verificar que lanza excepción 

+

138 with pytest.raises(InputNotProvided) as exc_info: 

+

139 chat_service.continue_conversation( 

+

140 conversation_id="test_chat_id", 

+

141 query=None, 

+

142 voice_file=None 

+

143 ) 

+

144 

+

145 assert str(exc_info.value) == "No input provided" 

+

146 

+

147 

+

148def test_continue_conversation_chat_not_found(): 

+

149 # Mocks de dependencias 

+

150 mock_agent = Mock() 

+

151 mock_db = Mock() 

+

152 mock_transcriber = Mock() 

+

153 

+

154 # Simular que el chat no existe en la base de datos 

+

155 mock_db.get_chat.return_value = None 

+

156 

+

157 # Instanciar el servicio 

+

158 chat_service = ChatService( 

+

159 agent=mock_agent, 

+

160 db=mock_db, 

+

161 transcriber=mock_transcriber 

+

162 ) 

+

163 

+

164 # Ejecutar el método y verificar que lanza excepción 

+

165 with pytest.raises(NoChatFound) as exc_info: 

+

166 chat_service.continue_conversation( 

+

167 conversation_id="non_existent_chat_id", 

+

168 query="Hola", 

+

169 voice_file=None 

+

170 ) 

+

171 

+

172 assert str(exc_info.value) == "Chat not found" 

+

173 

+

174 

+

175# test_usecases.py ubicado en tests/services 

+

176 

+

177import pytest 

+

178from unittest.mock import Mock, patch 

+

179from app.services.usecases import ChatService 

+

180from app.domain import models 

+

181 

+

182 

+

183def test_start_conversation(): 

+

184 # Mocks de dependencias 

+

185 mock_agent = Mock() 

+

186 mock_db = Mock() 

+

187 mock_transcriber = Mock() 

+

188 

+

189 # Instanciar el servicio 

+

190 chat_service = ChatService( 

+

191 agent=mock_agent, 

+

192 db=mock_db, 

+

193 transcriber=mock_transcriber 

+

194 ) 

+

195 

+

196 # Parchar el logger para evitar logs durante la prueba 

+

197 with patch('app.services.usecases.logger') as mock_logger: 

+

198 # Ejecutar el método 

+

199 chat_id = chat_service.start_conversation() 

+

200 

+

201 # Verificaciones 

+

202 # Verificar que save_chat fue llamado una vez 

+

203 mock_db.save_chat.assert_called_once() 

+

204 

+

205 # Obtener el chat que fue pasado a save_chat 

+

206 saved_chat = mock_db.save_chat.call_args[0][0] 

+

207 

+

208 # Verificar que se creó un objeto Chat 

+

209 assert isinstance(saved_chat, models.Chat) 

+

210 

+

211 # Verificar que el ID retornado coincide con el ID del chat guardado 

+

212 assert chat_id == saved_chat.id 

+

213 

+

214 # Verificar que se llamaron los logs correspondientes 

+

215 mock_logger.info.assert_any_call("Saving chat") 

+

216 mock_logger.info.assert_any_call("Chat saved") 

+

217 assert mock_logger.info.call_count == 2 

+
+ + + diff --git a/htmlcov/z_36f028580bb02cc8_test_py.html b/htmlcov/z_36f028580bb02cc8_test_py.html new file mode 100644 index 0000000..af38904 --- /dev/null +++ b/htmlcov/z_36f028580bb02cc8_test_py.html @@ -0,0 +1,124 @@ + + + + + Coverage for test\test.py: 100% + + + + + +
+
+

+ Coverage for test\test.py: + 100% +

+ +

+ 15 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-03 16:50 -0500 +

+ +
+
+
+

1from unittest.mock import MagicMock,patch 

+

2import pytest 

+

3 

+

4from app.services.usecases import ChatService 

+

5 

+

6from app.domain.models import Chat 

+

7 

+

8from app.domain.ports import ChatRepository, AgentPort, TranscriptionPort 

+

9 

+

10# Definir la prueba para el método start_conversation usando mocks 

+

11def test_start_conversation(): 

+

12 # Mocking de dependencias 

+

13 mock_agent = MagicMock(spec=AgentPort) 

+

14 mock_db = MagicMock(spec=ChatRepository) 

+

15 mock_transcriber = MagicMock(spec=TranscriptionPort) 

+

16 

+

17 # Instanciar el servicio con dependencias simuladas 

+

18 service = ChatService(agent=mock_agent, db=mock_db, transcriber=mock_transcriber) 

+

19 

+

20 # Ejecutar el método bajo prueba 

+

21 chat_id = service.start_conversation() 

+

22 

+

23 # Afirmaciones para verificar el comportamiento 

+

24 assert chat_id is not None # Verificar que se haya retornado un chat_id 

+

25 mock_db.save_chat.assert_called_once() # Asegurar que el método save_chat fue llamado una vez 

+

26 chat_saved = mock_db.save_chat.call_args[0][0] # Extraer el objeto Chat guardado 

+

27 assert isinstance(chat_saved,Chat) # Verificar que un objeto Chat fue guardado 

+
+ + + diff --git a/htmlcov/z_4c37ce8615b5aa70___init___py.html b/htmlcov/z_4c37ce8615b5aa70___init___py.html new file mode 100644 index 0000000..8330222 --- /dev/null +++ b/htmlcov/z_4c37ce8615b5aa70___init___py.html @@ -0,0 +1,97 @@ + + + + + Coverage for app\services\__init__.py: 100% + + + + + +
+
+

+ Coverage for app\services\__init__.py: + 100% +

+ +

+ 0 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-03 16:50 -0500 +

+ +
+
+
+
+ + + diff --git a/htmlcov/z_4c37ce8615b5aa70_usecases_py.html b/htmlcov/z_4c37ce8615b5aa70_usecases_py.html new file mode 100644 index 0000000..2fc2d59 --- /dev/null +++ b/htmlcov/z_4c37ce8615b5aa70_usecases_py.html @@ -0,0 +1,151 @@ + + + + + Coverage for app\services\usecases.py: 100% + + + + + +
+
+

+ Coverage for app\services\usecases.py: + 100% +

+ +

+ 34 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+ +
+
+
+

1from app.domain import ports, models 

+

2from app.logs import logger 

+

3 

+

4 

+

5class ChatService: 

+

6 def __init__( 

+

7 self, 

+

8 agent: ports.AgentPort, 

+

9 db: ports.ChatRepository, 

+

10 transcriber: ports.TranscriptionPort, 

+

11 ) -> None: 

+

12 self._agent = agent 

+

13 self._db = db 

+

14 self._transcriber = transcriber 

+

15 

+

16 def start_conversation(self) -> str: 

+

17 chat_model = models.Chat() 

+

18 logger.info("Saving chat") 

+

19 self._db.save_chat(chat_model) 

+

20 logger.info("Chat saved") 

+

21 return chat_model.id 

+

22 

+

23 def continue_conversation( 

+

24 self, 

+

25 conversation_id: str, 

+

26 query: str | None = None, 

+

27 voice_file: bytes | None = None, 

+

28 ) -> str: 

+

29 if voice_file: 

+

30 query = self._transcriber.transcribe_audio(voice_file) 

+

31 elif query: 

+

32 query = query 

+

33 else: 

+

34 raise InputNotProvided("No input provided") 

+

35 

+

36 chat = self._db.get_chat(conversation_id) 

+

37 if chat is None: 

+

38 raise NoChatFound("Chat not found") 

+

39 self._agent.set_memory_variables(chat.get_conversation_history()) 

+

40 self._agent(query=query) 

+

41 self._update_chat(chat) 

+

42 return self._agent.get_last_response() 

+

43 

+

44 def _update_chat(self, chat: models.Chat) -> None: 

+

45 chat = models.Chat(id=chat.id) 

+

46 chat.update_conversation(self._agent.get_conversation_history()) 

+

47 self._db.save_chat(chat) 

+

48 

+

49 

+

50class NoChatFound(Exception): 

+

51 pass 

+

52 

+

53class InputNotProvided(Exception): 

+

54 pass 

+
+ + + diff --git a/htmlcov/z_5f5a17c013354698___init___py.html b/htmlcov/z_5f5a17c013354698___init___py.html new file mode 100644 index 0000000..349989b --- /dev/null +++ b/htmlcov/z_5f5a17c013354698___init___py.html @@ -0,0 +1,97 @@ + + + + + Coverage for app\__init__.py: 100% + + + + + +
+
+

+ Coverage for app\__init__.py: + 100% +

+ +

+ 0 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-03 16:50 -0500 +

+ +
+
+
+
+ + + diff --git a/htmlcov/z_5f5a17c013354698_logs_py.html b/htmlcov/z_5f5a17c013354698_logs_py.html new file mode 100644 index 0000000..dd27f02 --- /dev/null +++ b/htmlcov/z_5f5a17c013354698_logs_py.html @@ -0,0 +1,121 @@ + + + + + Coverage for app\logs.py: 100% + + + + + +
+
+

+ Coverage for app\logs.py: + 100% +

+ +

+ 14 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-03 16:50 -0500 +

+ +
+
+
+

1import logging 

+

2import os 

+

3import sys 

+

4 

+

5format_ = ( 

+

6 "%(asctime)s | %(levelname)-7s | %(module)s.%(funcName)s:%(lineno)d | %(message)s" 

+

7) 

+

8 

+

9 

+

10def get_lambda_logger() -> logging.Logger: 

+

11 stdout_handler = logging.StreamHandler(sys.stdout) 

+

12 stdout_handler.setFormatter(logging.Formatter(format_)) 

+

13 logger_ = logging.getLogger( 

+

14 os.environ.get("AWS_LAMBDA_FUNCTION_NAME", "NoLambdaEnvironment") 

+

15 ) 

+

16 logger_.propagate = False 

+

17 logger_.setLevel(logging.INFO) 

+

18 # stdout_handler.setLevel(logging.INFO) 

+

19 stdout_handler.setLevel(logging.DEBUG) 

+

20 logger_.addHandler(stdout_handler) 

+

21 return logger_ 

+

22 

+

23 

+

24logger = get_lambda_logger() 

+
+ + + diff --git a/htmlcov/z_ad0ff7ef6dee06c8___init___py.html b/htmlcov/z_ad0ff7ef6dee06c8___init___py.html new file mode 100644 index 0000000..1a200ca --- /dev/null +++ b/htmlcov/z_ad0ff7ef6dee06c8___init___py.html @@ -0,0 +1,97 @@ + + + + + Coverage for app\domain\__init__.py: 100% + + + + + +
+
+

+ Coverage for app\domain\__init__.py: + 100% +

+ +

+ 0 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-03 16:50 -0500 +

+ +
+
+
+
+ + + diff --git a/htmlcov/z_ad0ff7ef6dee06c8_models_py.html b/htmlcov/z_ad0ff7ef6dee06c8_models_py.html new file mode 100644 index 0000000..815d1f3 --- /dev/null +++ b/htmlcov/z_ad0ff7ef6dee06c8_models_py.html @@ -0,0 +1,125 @@ + + + + + Coverage for app\domain\models.py: 100% + + + + + +
+
+

+ Coverage for app\domain\models.py: + 100% +

+ +

+ 15 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+ +
+
+
+

1from typing import cast 

+

2 

+

3import shortuuid 

+

4from langchain_core.messages import human, ai 

+

5from pydantic import v1 as pd1 

+

6 

+

7 

+

8def generate_uuid() -> str: 

+

9 return cast(str, shortuuid.uuid()) 

+

10 

+

11 

+

12# Entities 

+

13 

+

14 

+

15class Conversation(pd1.BaseModel): 

+

16 history: list[ai.AIMessage | human.HumanMessage] = pd1.Field(default_factory=list) 

+

17 

+

18 

+

19# Aggregates 

+

20class Chat(pd1.BaseModel): 

+

21 id: str = pd1.Field(default_factory=generate_uuid) 

+

22 conversation: Conversation = pd1.Field(default_factory=Conversation) 

+

23 

+

24 def update_conversation(self, current_conversation: list[ai.BaseMessage]) -> None: 

+

25 self.conversation.history = current_conversation 

+

26 

+

27 def get_conversation_history(self) -> list[ai.BaseMessage]: 

+

28 return self.conversation.history 

+
+ + + diff --git a/htmlcov/z_ad0ff7ef6dee06c8_ports_py.html b/htmlcov/z_ad0ff7ef6dee06c8_ports_py.html new file mode 100644 index 0000000..0f1d584 --- /dev/null +++ b/htmlcov/z_ad0ff7ef6dee06c8_ports_py.html @@ -0,0 +1,136 @@ + + + + + Coverage for app\domain\ports.py: 76% + + + + + +
+
+

+ Coverage for app\domain\ports.py: + 76% +

+ +

+ 29 statements   + + + +

+

+ « prev     + ^ index     + » next +       + coverage.py v7.6.1, + created at 2024-10-04 16:35 -0500 +

+ +
+
+
+

1import abc 

+

2from abc import ABC, abstractmethod 

+

3from typing import Any 

+

4 

+

5from langchain_core.messages import ai 

+

6 

+

7from app.domain import models 

+

8 

+

9 

+

10class ChatRepository(abc.ABC): 

+

11 @abc.abstractmethod 

+

12 def save_chat(self, chat: models.Chat) -> None: 

+

13 pass 

+

14 

+

15 @abc.abstractmethod 

+

16 def get_chat(self, chat_id: str) -> models.Chat | None: 

+

17 pass 

+

18 

+

19class AgentPort(abc.ABC): 

+

20 @abc.abstractmethod 

+

21 def __call__(self, query: str) -> dict[str, Any]: 

+

22 ... 

+

23 

+

24 @abc.abstractmethod 

+

25 def get_conversation_history(self) -> list[ai.BaseMessage]: 

+

26 ... 

+

27 

+

28 @abc.abstractmethod 

+

29 def set_memory_variables(self, history: list[ai.BaseMessage]) -> None: 

+

30 ... 

+

31 

+

32 @abc.abstractmethod 

+

33 def get_last_response(self) -> str: 

+

34 ... 

+

35 

+

36class TranscriptionPort(ABC): 

+

37 @abstractmethod 

+

38 def transcribe_audio(self, audio_file: bytes) -> str: 

+

39 pass 

+
+ + + diff --git a/poetry.lock b/poetry.lock index 4cdd109..ebecf49 100644 --- a/poetry.lock +++ b/poetry.lock @@ -414,6 +414,90 @@ files = [ {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, ] +[[package]] +name = "coverage" +version = "7.6.1" +description = "Code coverage measurement for Python" +optional = false +python-versions = ">=3.8" +files = [ + {file = "coverage-7.6.1-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b06079abebbc0e89e6163b8e8f0e16270124c154dc6e4a47b413dd538859af16"}, + {file = "coverage-7.6.1-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cf4b19715bccd7ee27b6b120e7e9dd56037b9c0681dcc1adc9ba9db3d417fa36"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e61c0abb4c85b095a784ef23fdd4aede7a2628478e7baba7c5e3deba61070a02"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fd21f6ae3f08b41004dfb433fa895d858f3f5979e7762d052b12aef444e29afc"}, + {file = "coverage-7.6.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8f59d57baca39b32db42b83b2a7ba6f47ad9c394ec2076b084c3f029b7afca23"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:a1ac0ae2b8bd743b88ed0502544847c3053d7171a3cff9228af618a068ed9c34"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:e6a08c0be454c3b3beb105c0596ebdc2371fab6bb90c0c0297f4e58fd7e1012c"}, + {file = "coverage-7.6.1-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:f5796e664fe802da4f57a168c85359a8fbf3eab5e55cd4e4569fbacecc903959"}, + {file = "coverage-7.6.1-cp310-cp310-win32.whl", hash = "sha256:7bb65125fcbef8d989fa1dd0e8a060999497629ca5b0efbca209588a73356232"}, + {file = "coverage-7.6.1-cp310-cp310-win_amd64.whl", hash = "sha256:3115a95daa9bdba70aea750db7b96b37259a81a709223c8448fa97727d546fe0"}, + {file = "coverage-7.6.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:7dea0889685db8550f839fa202744652e87c60015029ce3f60e006f8c4462c93"}, + {file = "coverage-7.6.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:ed37bd3c3b063412f7620464a9ac1314d33100329f39799255fb8d3027da50d3"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d85f5e9a5f8b73e2350097c3756ef7e785f55bd71205defa0bfdaf96c31616ff"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9bc572be474cafb617672c43fe989d6e48d3c83af02ce8de73fff1c6bb3c198d"}, + {file = "coverage-7.6.1-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0c0420b573964c760df9e9e86d1a9a622d0d27f417e1a949a8a66dd7bcee7bc6"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1f4aa8219db826ce6be7099d559f8ec311549bfc4046f7f9fe9b5cea5c581c56"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:fc5a77d0c516700ebad189b587de289a20a78324bc54baee03dd486f0855d234"}, + {file = "coverage-7.6.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:b48f312cca9621272ae49008c7f613337c53fadca647d6384cc129d2996d1133"}, + {file = "coverage-7.6.1-cp311-cp311-win32.whl", hash = "sha256:1125ca0e5fd475cbbba3bb67ae20bd2c23a98fac4e32412883f9bcbaa81c314c"}, + {file = "coverage-7.6.1-cp311-cp311-win_amd64.whl", hash = "sha256:8ae539519c4c040c5ffd0632784e21b2f03fc1340752af711f33e5be83a9d6c6"}, + {file = "coverage-7.6.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:95cae0efeb032af8458fc27d191f85d1717b1d4e49f7cb226cf526ff28179778"}, + {file = "coverage-7.6.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:5621a9175cf9d0b0c84c2ef2b12e9f5f5071357c4d2ea6ca1cf01814f45d2391"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:260933720fdcd75340e7dbe9060655aff3af1f0c5d20f46b57f262ab6c86a5e8"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:07e2ca0ad381b91350c0ed49d52699b625aab2b44b65e1b4e02fa9df0e92ad2d"}, + {file = "coverage-7.6.1-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c44fee9975f04b33331cb8eb272827111efc8930cfd582e0320613263ca849ca"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:877abb17e6339d96bf08e7a622d05095e72b71f8afd8a9fefc82cf30ed944163"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:3e0cadcf6733c09154b461f1ca72d5416635e5e4ec4e536192180d34ec160f8a"}, + {file = "coverage-7.6.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c3c02d12f837d9683e5ab2f3d9844dc57655b92c74e286c262e0fc54213c216d"}, + {file = "coverage-7.6.1-cp312-cp312-win32.whl", hash = "sha256:e05882b70b87a18d937ca6768ff33cc3f72847cbc4de4491c8e73880766718e5"}, + {file = "coverage-7.6.1-cp312-cp312-win_amd64.whl", hash = "sha256:b5d7b556859dd85f3a541db6a4e0167b86e7273e1cdc973e5b175166bb634fdb"}, + {file = "coverage-7.6.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a4acd025ecc06185ba2b801f2de85546e0b8ac787cf9d3b06e7e2a69f925b106"}, + {file = "coverage-7.6.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a6d3adcf24b624a7b778533480e32434a39ad8fa30c315208f6d3e5542aeb6e9"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d0c212c49b6c10e6951362f7c6df3329f04c2b1c28499563d4035d964ab8e08c"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6e81d7a3e58882450ec4186ca59a3f20a5d4440f25b1cff6f0902ad890e6748a"}, + {file = "coverage-7.6.1-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:78b260de9790fd81e69401c2dc8b17da47c8038176a79092a89cb2b7d945d060"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a78d169acd38300060b28d600344a803628c3fd585c912cacc9ea8790fe96862"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:2c09f4ce52cb99dd7505cd0fc8e0e37c77b87f46bc9c1eb03fe3bc9991085388"}, + {file = "coverage-7.6.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:6878ef48d4227aace338d88c48738a4258213cd7b74fd9a3d4d7582bb1d8a155"}, + {file = "coverage-7.6.1-cp313-cp313-win32.whl", hash = "sha256:44df346d5215a8c0e360307d46ffaabe0f5d3502c8a1cefd700b34baf31d411a"}, + {file = "coverage-7.6.1-cp313-cp313-win_amd64.whl", hash = "sha256:8284cf8c0dd272a247bc154eb6c95548722dce90d098c17a883ed36e67cdb129"}, + {file = "coverage-7.6.1-cp313-cp313t-macosx_10_13_x86_64.whl", hash = "sha256:d3296782ca4eab572a1a4eca686d8bfb00226300dcefdf43faa25b5242ab8a3e"}, + {file = "coverage-7.6.1-cp313-cp313t-macosx_11_0_arm64.whl", hash = "sha256:502753043567491d3ff6d08629270127e0c31d4184c4c8d98f92c26f65019962"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6a89ecca80709d4076b95f89f308544ec8f7b4727e8a547913a35f16717856cb"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a318d68e92e80af8b00fa99609796fdbcdfef3629c77c6283566c6f02c6d6704"}, + {file = "coverage-7.6.1-cp313-cp313t-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13b0a73a0896988f053e4fbb7de6d93388e6dd292b0d87ee51d106f2c11b465b"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_aarch64.whl", hash = "sha256:4421712dbfc5562150f7554f13dde997a2e932a6b5f352edcce948a815efee6f"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_i686.whl", hash = "sha256:166811d20dfea725e2e4baa71fffd6c968a958577848d2131f39b60043400223"}, + {file = "coverage-7.6.1-cp313-cp313t-musllinux_1_2_x86_64.whl", hash = "sha256:225667980479a17db1048cb2bf8bfb39b8e5be8f164b8f6628b64f78a72cf9d3"}, + {file = "coverage-7.6.1-cp313-cp313t-win32.whl", hash = "sha256:170d444ab405852903b7d04ea9ae9b98f98ab6d7e63e1115e82620807519797f"}, + {file = "coverage-7.6.1-cp313-cp313t-win_amd64.whl", hash = "sha256:b9f222de8cded79c49bf184bdbc06630d4c58eec9459b939b4a690c82ed05657"}, + {file = "coverage-7.6.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6db04803b6c7291985a761004e9060b2bca08da6d04f26a7f2294b8623a0c1a0"}, + {file = "coverage-7.6.1-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:f1adfc8ac319e1a348af294106bc6a8458a0f1633cc62a1446aebc30c5fa186a"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a95324a9de9650a729239daea117df21f4b9868ce32e63f8b650ebe6cef5595b"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b43c03669dc4618ec25270b06ecd3ee4fa94c7f9b3c14bae6571ca00ef98b0d3"}, + {file = "coverage-7.6.1-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8929543a7192c13d177b770008bc4e8119f2e1f881d563fc6b6305d2d0ebe9de"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:a09ece4a69cf399510c8ab25e0950d9cf2b42f7b3cb0374f95d2e2ff594478a6"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:9054a0754de38d9dbd01a46621636689124d666bad1936d76c0341f7d71bf569"}, + {file = "coverage-7.6.1-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:0dbde0f4aa9a16fa4d754356a8f2e36296ff4d83994b2c9d8398aa32f222f989"}, + {file = "coverage-7.6.1-cp38-cp38-win32.whl", hash = "sha256:da511e6ad4f7323ee5702e6633085fb76c2f893aaf8ce4c51a0ba4fc07580ea7"}, + {file = "coverage-7.6.1-cp38-cp38-win_amd64.whl", hash = "sha256:3f1156e3e8f2872197af3840d8ad307a9dd18e615dc64d9ee41696f287c57ad8"}, + {file = "coverage-7.6.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:abd5fd0db5f4dc9289408aaf34908072f805ff7792632250dcb36dc591d24255"}, + {file = "coverage-7.6.1-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:547f45fa1a93154bd82050a7f3cddbc1a7a4dd2a9bf5cb7d06f4ae29fe94eaf8"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:645786266c8f18a931b65bfcefdbf6952dd0dea98feee39bd188607a9d307ed2"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9e0b2df163b8ed01d515807af24f63de04bebcecbd6c3bfeff88385789fdf75a"}, + {file = "coverage-7.6.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:609b06f178fe8e9f89ef676532760ec0b4deea15e9969bf754b37f7c40326dbc"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:702855feff378050ae4f741045e19a32d57d19f3e0676d589df0575008ea5004"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:2bdb062ea438f22d99cba0d7829c2ef0af1d768d1e4a4f528087224c90b132cb"}, + {file = "coverage-7.6.1-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:9c56863d44bd1c4fe2abb8a4d6f5371d197f1ac0ebdee542f07f35895fc07f36"}, + {file = "coverage-7.6.1-cp39-cp39-win32.whl", hash = "sha256:6e2cd258d7d927d09493c8df1ce9174ad01b381d4729a9d8d4e38670ca24774c"}, + {file = "coverage-7.6.1-cp39-cp39-win_amd64.whl", hash = "sha256:06a737c882bd26d0d6ee7269b20b12f14a8704807a01056c80bb881a4b2ce6ca"}, + {file = "coverage-7.6.1-pp38.pp39.pp310-none-any.whl", hash = "sha256:e9a6e0eb86070e8ccaedfbd9d38fec54864f3125ab95419970575b42af7541df"}, + {file = "coverage-7.6.1.tar.gz", hash = "sha256:953510dfb7b12ab69d20135a0662397f077c59b1e6379a768e97c59d852ee51d"}, +] + +[package.extras] +toml = ["tomli"] + [[package]] name = "dataclasses-json" version = "0.6.7" @@ -2103,4 +2187,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "2444438026f1b76defa5644ca632725b91000ec28af9954c3fe93c80eda564c4" +content-hash = "3fa9b04d14318132e5ea89fa54e0b589e18a2747b1b33e3ce3c50b77aafd257e" diff --git a/pyproject.toml b/pyproject.toml index beab032..2daf070 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ python-multipart = "^0.0.11" shortuuid = "^1.0.13" boto3 = "^1.35.29" langfuse = "^2.51.2" +coverage = "^7.6.1" [tool.poetry.group.dev.dependencies] black = "^24.8.0" diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test2.py b/test/test2.py new file mode 100644 index 0000000..c12e098 --- /dev/null +++ b/test/test2.py @@ -0,0 +1,174 @@ + +import pytest +from unittest.mock import Mock +from app.services.usecases import ChatService, InputNotProvided, NoChatFound +from app.domain import models +from unittest.mock import Mock, patch + + +def test_update_chat(): + mock_agent = Mock() + conversation_history = [ + {"type": "human", "content": "Hola"}, + {"type": "ai", "content": "Hola, ¿en qué puedo ayudarte?"} + ] + mock_agent.get_conversation_history.return_value = conversation_history + + mock_db = Mock() + + mock_transcriber = Mock() + + chat_service = ChatService( + agent=mock_agent, + db=mock_db, + transcriber=mock_transcriber + ) + + chat = models.Chat(id="test_chat_id") + + chat_service._update_chat(chat) + + mock_agent.get_conversation_history.assert_called_once() + + expected_chat = models.Chat(id="test_chat_id") + expected_chat.update_conversation(conversation_history) + + saved_chat = mock_db.save_chat.call_args[0][0] + + assert saved_chat.id == expected_chat.id + assert saved_chat.conversation.history == expected_chat.conversation.history + + + + + +def test_continue_conversation_with_query(): + mock_agent = Mock() + mock_agent.get_last_response.return_value = "Respuesta del agente" + mock_db = Mock() + mock_transcriber = Mock() + + chat = models.Chat(id="test_chat_id") + mock_db.get_chat.return_value = chat + + chat_service = ChatService( + agent=mock_agent, + db=mock_db, + transcriber=mock_transcriber + ) + + response = chat_service.continue_conversation( + conversation_id="test_chat_id", + query="Hola", + voice_file=None + ) + + mock_db.get_chat.assert_called_once_with("test_chat_id") + mock_agent.set_memory_variables.assert_called_once_with(chat.get_conversation_history()) + mock_agent.assert_called_once_with(query="Hola") + mock_db.save_chat.assert_called_once() + assert response == "Respuesta del agente" + + +def test_continue_conversation_with_voice_file(): + mock_agent = Mock() + mock_agent.get_last_response.return_value = "Respuesta del agente" + mock_db = Mock() + mock_transcriber = Mock() + mock_transcriber.transcribe_audio.return_value = "Texto transcrito" + + chat = models.Chat(id="test_chat_id") + mock_db.get_chat.return_value = chat + + chat_service = ChatService( + agent=mock_agent, + db=mock_db, + transcriber=mock_transcriber + ) + + response = chat_service.continue_conversation( + conversation_id="test_chat_id", + query=None, + voice_file=b"archivo de audio" + ) + + mock_transcriber.transcribe_audio.assert_called_once_with(b"archivo de audio") + mock_db.get_chat.assert_called_once_with("test_chat_id") + mock_agent.set_memory_variables.assert_called_once_with(chat.get_conversation_history()) + mock_agent.assert_called_once_with(query="Texto transcrito") + mock_db.save_chat.assert_called_once() + assert response == "Respuesta del agente" + + +def test_continue_conversation_no_input(): + mock_agent = Mock() + mock_db = Mock() + mock_transcriber = Mock() + + chat_service = ChatService( + agent=mock_agent, + db=mock_db, + transcriber=mock_transcriber + ) + + with pytest.raises(InputNotProvided) as exc_info: + chat_service.continue_conversation( + conversation_id="test_chat_id", + query=None, + voice_file=None + ) + + assert str(exc_info.value) == "No input provided" + + +def test_continue_conversation_chat_not_found(): + mock_agent = Mock() + mock_db = Mock() + mock_transcriber = Mock() + + mock_db.get_chat.return_value = None + + chat_service = ChatService( + agent=mock_agent, + db=mock_db, + transcriber=mock_transcriber + ) + + with pytest.raises(NoChatFound) as exc_info: + chat_service.continue_conversation( + conversation_id="non_existent_chat_id", + query="Hola", + voice_file=None + ) + + assert str(exc_info.value) == "Chat not found" + + + + + +def test_start_conversation(): + mock_agent = Mock() + mock_db = Mock() + mock_transcriber = Mock() + + chat_service = ChatService( + agent=mock_agent, + db=mock_db, + transcriber=mock_transcriber + ) + + with patch('app.services.usecases.logger') as mock_logger: + chat_id = chat_service.start_conversation() + + mock_db.save_chat.assert_called_once() + + saved_chat = mock_db.save_chat.call_args[0][0] + + assert isinstance(saved_chat, models.Chat) + + assert chat_id == saved_chat.id + + mock_logger.info.assert_any_call("Saving chat") + mock_logger.info.assert_any_call("Chat saved") + assert mock_logger.info.call_count == 2